Codeforces Round 431 (Div. 1) |
---|
Finished |
I won't feel lonely, nor will I be sorrowful... not before everything is buried.
A string of n beads is left as the message of leaving. The beads are numbered from 1 to n from left to right, each having a shape numbered by integers between 1 and n inclusive. Some beads may have the same shapes.
The memory of a shape x in a certain subsegment of beads, is defined to be the difference between the last position and the first position that shape x appears in the segment. The memory of a subsegment is the sum of memories over all shapes that occur in it.
From time to time, shapes of beads change as well as the memories. Sometimes, the past secreted in subsegments are being recalled, and you are to find the memory for each of them.
The first line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 100 000) — the number of beads in the string, and the total number of changes and queries, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — the initial shapes of beads 1, 2, ..., n, respectively.
The following m lines each describes either a change in the beads or a query of subsegment. A line has one of the following formats:
For each query, print one line with an integer — the memory of the recalled subsegment.
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
5
0
7
1
7 5
1 3 2 1 4 2 3
1 1 4
2 2 3
1 1 7
2 4 5
1 1 7
0
0
The initial string of beads has shapes (1, 2, 3, 1, 3, 2, 1).
Consider the changes and queries in their order:
Name |
---|