array(2019CCPC网络预选赛 hdu6703主席树+set)主席树求大于等于k的最小值
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:
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.
Sample Input
3
5 9
4 3 1 2 5
2 1 1
2 2 2
2 6 7
2 1 3
2 6 3
2 0 4
1 5
2 3 7
2 4 3
10 6
1 2 4 6 3 5 9 10 7 8
2 7 2
1 2
2 0 5
2 11 10
1 3
2 3 2
10 10
9 7 5 3 4 10 6 2 1 8
1 10
2 8 9
1 12
2 15 15
1 12
2 1 3
1 9
1 12
2 2 2
1 9
Sample Output
1
5
2
2
5
6
1
6
7
3
11
10
11
4
8
11
Hint
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
昨天卡了很久的一個(gè)題,你開(kāi)始線(xiàn)段樹(shù)+set一直超時(shí),后來(lái)改了主席樹(shù),但是還是卡了很久。。
題意:要找出一個(gè)數(shù),這個(gè)數(shù)在1~r中不能出現(xiàn)過(guò),并且還要不小于k。并且讀入的數(shù)據(jù)還都要異或上上一次的答案。
一開(kāi)始理解錯(cuò)了,以為必須是數(shù)組里的數(shù)才行。但是第一個(gè)樣例中就有一個(gè)數(shù)不是數(shù)組里的數(shù),除此之外,題目中有說(shuō)所有的數(shù)都是獨(dú)一無(wú)二的。在執(zhí)行操作1的時(shí)候,一個(gè)數(shù)加上1e7之后,就相當(dāng)于作廢了。因?yàn)閿?shù)組中所有的數(shù)字都是不大于1e5的,所以異或之后的值也是不大于1e5的。這樣的話(huà),在加上1e7之后,就相當(dāng)于這個(gè)值在1~r中刪除了,又可以再用了。那這樣我們把這樣的值存到一個(gè)set里面,r+1到n的值用主席樹(shù)去求。主席樹(shù)是好多權(quán)值線(xiàn)段樹(shù)的集合,是按著權(quán)值來(lái)的,存的是每個(gè)數(shù)的出現(xiàn)的個(gè)數(shù)。用主席樹(shù)去求r+1 ~ n中大于等于k最小的數(shù)。
代碼如下:
昨天寫(xiě)的超時(shí)的代碼(線(xiàn)段樹(shù)+set)當(dāng)個(gè)借鑒吧
代碼如下:
努力加油a啊,(o)/~
總結(jié)
以上是生活随笔為你收集整理的array(2019CCPC网络预选赛 hdu6703主席树+set)主席树求大于等于k的最小值的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 热狗树 树形dp(中国石油大学我要变强
- 下一篇: Lost Cows POJ - 2182