Problem Description You are given an array a1,a2,…,an(?i∈[1,n],1≤ai≤n). Initially, each element of the array is unique.
Moreover, there are m instructions.
Each instruction is in one of the following two formats:
(1,pos),indicating to change the value of apos to apos+10,000,000;
(2,r,k),indicating to ask the minimum value which is not equal to any ai ( 1≤i≤r ) and **not less ** than k.
Please print all results of the instructions in format 2.
Input The first line of the input contains an integer T(1≤T≤10), denoting the number of test cases.
In each test case, there are two integers n(1≤n≤100,000),m(1≤m≤100,000) in the first line, denoting the size of array a and the number of instructions.
In the second line, there are n distinct integers a1,a2,…,an (?i∈[1,n],1≤ai≤n),denoting the array. For the following m lines, each line is of format (1,t1) or (2,t2,t3). The parameters of each instruction are generated by such way :
For instructions in format 1 , we defined pos=t1⊕LastAns . (It is promised that 1≤pos≤n)
For instructions in format 2 , we defined r=t2⊕LastAns,k=t3⊕LastAns. (It is promised that 1≤r≤n,1≤k≤n )
(Note that ⊕ means the bitwise XOR operator. )
Before the first instruction of each test case, LastAns is equal to 0 .After each instruction in format 2, LastAns will be changed to the result of that instruction.
(∑n≤510,000,∑m≤510,000 )
Output For each instruction in format 2, output the answer in one line.
note: After the generation procedure ,the instructions of the first test case are : 2 1 1, in format 2 and r=1 , k=1 2 3 3, in format 2 and r=3 , k=3 2 3 2, in format 2 and r=3 , k=2 2 3 1, in format 2 and r=3 , k=1 2 4 1, in format 2 and r=4 , k=1 2 5 1, in format 2 and r=5 , k=1 1 3 , in format 1 and pos=3 2 5 1, in format 2 and r=5 , k=1 2 5 2, in format 2 and r=5 , k=2
the instructions of the second test case are : 2 7 2, in format 2 and r=7 , k=2 1 5 , in format 1 and pos=5 2 7 2, in format 2 and r=7 , k=2 2 8 9, in format 2 and r=8 , k=9 1 8 , in format 1 and pos=8 2 8 9, in format 2 and r=8 , k=9
the instructions of the third test case are : 1 10 , in format 1 and pos=10 2 8 9 , in format 2 and r=8 , k=9 1 7 , in format 1 and pos=7 2 4 4 , in format 2 and r=4 , k=4 1 8 , in format 1 and pos=8 2 5 7 , in format 2 and r=5 , k=7 1 1 , in format 1 and pos=1 1 4 , in format 1 and pos=4 2 10 10, in format 2 and r=10 , k=10 1 2 , in format 1 and pos=2 昨天卡了很久的一個題,你開始線段樹+set一直超時,后來改了主席樹,但是還是卡了很久。。 題意:要找出一個數,這個數在1~r中不能出現過,并且還要不小于k。并且讀入的數據還都要異或上上一次的答案。 一開始理解錯了,以為必須是數組里的數才行。但是第一個樣例中就有一個數不是數組里的數,除此之外,題目中有說所有的數都是獨一無二的。在執行操作1的時候,一個數加上1e7之后,就相當于作廢了。因為數組中所有的數字都是不大于1e5的,所以異或之后的值也是不大于1e5的。這樣的話,在加上1e7之后,就相當于這個值在1~r中刪除了,又可以再用了。那這樣我們把這樣的值存到一個set里面,r+1到n的值用主席樹去求。主席樹是好多權值線段樹的集合,是按著權值來的,存的是每個數的出現的個數。用主席樹去求r+1 ~ n中大于等于k最小的數。 代碼如下: