PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000054. Kỷ vật chia xa (Goodbye Souvenir)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Kỷ vật chia xa (Goodbye Souvenir)

Goodbye Souvenir

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An array of nn beads has shape labels ai∈[1,n]a_i\in[1,n]. In a queried interval [l,r][l,r], each shape contributes the distance between its last and first occurrences within that interval. A shape appearing once contributes zero. The interval's memory is the sum of these contributions.

Process:

  • 1 p x: change the shape at position pp to xx.
  • 2 l r: report the current memory of the inclusive interval [l,r][l,r].

Input

The first line contains n,mn,m and the next line contains the nn labels ai∈[1,n]a_i\in[1,n]. The next mm lines are 1 p x or 2 l r, with valid one-indexed positions and l≤rl\le r for range queries.

Output

Print one integer per type-2 query.

Subtasks

  • Subtask 1 (10 points): 1≤n≤801\le n\le80; 1≤q≤1001\le q\le100. Every color label lies in [1,n][1,n].
  • Subtask 2 (20 points): 1≤n≤30001\le n\le3000; 1≤q≤30001\le q\le3000. Every color label lies in [1,n][1,n].
  • Subtask 3 (25 points): 1≤n≤250001\le n\le25000; 1≤q≤250001\le q\le25000. Every color label lies in [1,n][1,n].
  • Subtask 4 (45 points): 1≤n≤1000001\le n\le100000; 1≤q≤1000001\le q\le100000. Every color label lies in [1,n][1,n].

Examples

Input

7 6
1 2 3 1 3 2 1
2 3 7
2 1 3
1 7 2
1 3 2
2 1 6
2 5 7

Output

5
0
7
1

Explanation

In interval [3,7][3,7], shape 11 occurs at 4,74,7 and contributes 33; shape 33 occurs at 3,53,5 and contributes 22; all others contribute zero, so the answer is 55. Interval [1,3][1,3] has no repeated shape and gives 00. After the updates, the final two queries yield 77 and 11.