#P7502. Multiset XOR Queries
Multiset XOR Queries
Multiset XOR Queries
You are required to maintain a multiset (i.e. a collection that allows duplicate elements) of ordered pairs of natural numbers. The multiset supports the following three operations:
- Insert: Insert a natural number pair (x, y) into the multiset.
- Delete: Remove a natural number pair (x, y) from the multiset. It is guaranteed that the pair exists in the multiset at the time of deletion.
- Query: Given a natural number pair \( (x, y) \), count how many pairs \( (a, b) \) in the multiset satisfy the condition \[ x \operatorname{xor} a > y \operatorname{xor} b \] where \( \operatorname{xor} \) represents the bitwise exclusive-or operation.
Note: All pairs mentioned in this problem are ordered pairs.
inputFormat
The first line contains an integer \( Q \) representing the number of operations.
Each of the following \( Q \) lines contains an operation in one of the following formats:
- 1 x y — Insert the pair \( (x, y) \) into the multiset.
- 2 x y — Delete the pair \( (x, y) \) from the multiset. It is guaranteed that this pair exists in the multiset.
- 3 x y — Query: output the number of pairs \( (a, b) \) in the multiset such that \( x \operatorname{xor} a > y \operatorname{xor} b \).
outputFormat
For each query operation (operation type 3), output a single line containing the integer answer.
sample
5
1 1 2
1 3 4
3 0 0
2 1 2
3 1 2
0
0
</p>