#abc308g. G - Minimum Xor Pair Query

G - Minimum Xor Pair Query

Score : 600600 points

问题描述

在一块黑板上,你可以写入整数。初始时,黑板上没有写任何整数。给定 QQ 个查询,按顺序处理它们。

查询有以下三种类型:

  • 1 x:在黑板上写入一个整数xx

  • 2 x:从黑板上擦除一个整数xx。在执行此查询时,保证至少有一个xx已经被写在了黑板上。

  • 3:打印黑板上所写两个整数之间可能的最小按位异或值。在处理此查询时,保证至少有两个整数被写在了黑板上。

什么是按位异或?非负整数 AABB 的按位异或(bitwise XOR),记作 ABA \oplus B,定义如下:

  • ABA \oplus B 转换为二进制表示时,第 2k2^k 位(k0k \geq 0)为 11 当且仅当 AABB 在相应位置上的 2k2^k 位只有一个为 11,否则为 00

例如,35=63 \oplus 5 = 6(以二进制表示:011101=110011 \oplus 101 = 110)。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a blackboard on which you can write integers. Initially, no integer is written on the blackboard. Given QQ queries, process them in order.

The query is of one of the following three kinds:

  • 1 x : write an xx on the blackboard.

  • 2 x : erase an xx from the blackboard. At the point this query is given, it is guaranteed that at least one xx is written on the blackboard.

  • 3 : print the minimum possible bitwise XOR of two of the integers written on the blackboard. At the point this query is processed, it is guaranteed that at least two integers are written on the blackboard.

What is bitwise XOR? The bitwise XOR of non-negative integers AA and BB, ABA \oplus B, is defined as follows.

  • When ABA \oplus B is written in binary, the 2k2^ks place (k0k \geq 0) is 11 if exactly one of the 2k2^ks places of AA and BB is 11, and 00 otherwise.

For instance, 35=63 \oplus 5 = 6 (in binary: 011101=110011 \oplus 101 = 110).

Constraints

  • 1Q3×1051\leq Q \leq 3\times 10^5
  • 0x<2300\leq x < 2 ^{30}
  • When a query 22 is given, at least one xx is written on the blackboard.
  • When a query 33 is given, at least two integers are written on the blackboard.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

QQ

query1\mathrm{query}_1

query2\mathrm{query}_2

\vdots

queryQ\mathrm{query}_Q

In the ii-th query, queryi\mathrm{query}_i, the kind of query, cic_i (one of 11, 22, or 33), is first given. If ci=1c_i = 1 or ci=2c_i = 2, an integer xx is additionally given.

In other words, each query is in one of the following three formats.

11 xx

22 xx

33

Output

Print qq lines, where qq is the number of queries such that ci=3c_i=3.

The jj-th (1jq)(1\leq j\leq q) line should contain the answer to the jj-th such query.

Sample Input 1

9
1 2
1 10
3
1 3
3
2 2
3
1 10
3

Sample Output 1

8
1
9
0

After processing the 11-st query, a 22 is written on the blackboard.

After processing the 22-nd query, a 22 and a 1010 are written on the blackboard.

When processing the 33-rd query, the minimum possible bitwise XOR of two of the integers written on the backboard is 210=82\oplus 10=8.

After processing the 44-th query, a 22, a 33, and a 1010 are written on the blackboard.

When processing the 55-th query, the minimum possible bitwise XOR of two of the integers written on the backboard is 23=12\oplus 3=1.

After processing the 66-th query, a 33 and a 1010 are written on the blackboard.

When processing the 77-th query, the minimum possible bitwise XOR of two of the integers written on the backboard is 310=93\oplus 10=9.

After processing the 88-th query, a 33 and two 1010s are written on the blackboard.

When processing the 99-th query, the minimum possible bitwise XOR of two of the integers written on the backboard is 1010=010\oplus 10=0.

update @ 2024/3/10 08:45:14

}