Posted onSymbols count in article: 1.2kReading time ≈4 mins.
Problem
【ACM-ICPC 2018 南京赛区网络预赛】Set
TimeLimit:1500ms MemoryLimit:524288K
Description
Shinku is very interested in the set. One day, she got n sets, and the ith number ai is in the ith set. But she doesn’t think it is interesting enough, so she applies m magic to these sets. There are three kinds of magic:
1uv: If the uth and vth numbers are not in one set, then the Shinku’s magic will merge the set containing the uth number and the set containing the vth number.
2u: Shinku’s magic adds 1 to each number in the set containing the uth number.
3ukx: Shinku can immediately know how many numbers t in the set containing the uth number satisfy t≡x(mod2k)(0≤k≤30,0≤x<2k).
But unfortunately, for some reason the type 3 magic fails. So Shinku wants you to tell her the answer after every type 3 magic.
Note that there can be multiple numbers with the same value in one set, that is, numbers with the same value will not disappear when merged.
Input
The first line contains two integers n,m(1≤n,m≤6×105), the number of initial sets and the number of the magic.
The second line contains n integers. The ith number ai(0≤ai≤109) is the number in the ith set initially.
The next m lines describe the sequence of magic. The ith line describes the ith magic. Each magic is a magic as described above.
Output
For each type 3 magic, output the answer you are asked to calculate.
Sample Input
1 2 3 4 5 6 7
3 5 2 3 4 1 1 3 3 3 1 0 2 2 1 2 3 3 3 1 0
Sample Output
1 2
2 3
Explanation
After the first operation, the numbers are 2,3,4, sets are {2,4}{3}
For the second operation, the third number is in {2,4}, 2≡0(mod21), 4≡0(mod21), so the answer is 2.
After the third operation, the numbers are 2,4,4, sets are {2,4}{4}
After the forth operation, the numbers are 2,4,4, sets are {2,4,4}
For the fifth operation, ,the third number is in {2,4,4}, 2≡0(mod21), 4≡0(mod21),4≡0(mod21), so the answer is 3.