CF848C.Goodbye Souvenir

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

I won't feel lonely, nor will I be sorrowful... not before everything is buried.

A string of nn beads is left as the message of leaving. The beads are numbered from 11 to nn from left to right, each having a shape numbered by integers between 11 and nn inclusive. Some beads may have the same shapes.

The memory of a shape xx in a certain subsegment of beads, is defined to be the difference between the last position and the first position that shape xx 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 nn and mm ( 1<=n,m<=1000001<=n,m<=100000 ) — the number of beads in the string, and the total number of changes and queries, respectively.

The second line contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=n1<=a_{i}<=n ) — the initial shapes of beads 1,2,...,n1,2,...,n , respectively.

The following mm lines each describes either a change in the beads or a query of subsegment. A line has one of the following formats:

  • 1 p x ( 1<=p<=n1<=p<=n , 1<=x<=n1<=x<=n ), meaning that the shape of the pp -th bead is changed into xx ;
  • 2 l r ( 1<=l<=r<=n1<=l<=r<=n ), denoting a query of memory of the subsegment from ll to rr , inclusive.

输出格式

For each query, print one line with an integer — the memory of the recalled subsegment.

输入输出样例

  • 输入#1

    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
    

    输出#1

    5
    0
    7
    1
    
  • 输入#2

    7 5
    1 3 2 1 4 2 3
    1 1 4
    2 2 3
    1 1 7
    2 4 5
    1 1 7
    

    输出#2

    0
    0
    

说明/提示

The initial string of beads has shapes (1,2,3,1,3,2,1)(1,2,3,1,3,2,1) .

Consider the changes and queries in their order:

  1. 2 3 7: the memory of the subsegment [3,7][3,7] is (74)+(66)+(53)=5(7-4)+(6-6)+(5-3)=5 ;
  2. 2 1 3: the memory of the subsegment [1,3][1,3] is (11)+(22)+(33)=0(1-1)+(2-2)+(3-3)=0 ;
  3. 1 7 2: the shape of the 77 -th bead changes into 22 . Beads now have shapes (1,2,3,1,3,2,2)(1,2,3,1,3,2,2) respectively;
  4. 1 3 2: the shape of the 33 -rd bead changes into 22 . Beads now have shapes (1,2,2,1,3,2,2)(1,2,2,1,3,2,2) respectively;
  5. 2 1 6: the memory of the subsegment [1,6][1,6] is (41)+(62)+(55)=7(4-1)+(6-2)+(5-5)=7 ;
  6. 2 5 7: the memory of the subsegment [5,7][5,7] is (76)+(55)=1(7-6)+(5-5)=1 .
首页