G - Minimum Xor Pair Query Editorial /

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600600

問題文

整数を書くことができる黒板があります。はじめ黒板には整数は何も書かれていません。クエリが QQ 個与えられるので順に処理してください。

クエリは以下の 33 種類です。

  • 1 x : 黒板に xx を一つ書き込む。

  • 2 x : 黒板に書かれた xx を一つ消去する。このクエリが与えられるとき、黒板に xx が一つ以上書かれていることが保証される。

  • 3 : 黒板に書かれた二つの整数のビット単位 XOR としてあり得る最小値を出力する。このクエリを処理する際、黒板に整数が二つ以上書かれていることが保証される。

ビット単位 XOR とは 非負整数 A,BA, B のビット単位 XOR 、ABA \oplus B は、以下のように定義されます。
  • ABA \oplus B を二進表記した際の 2k2^k (k0k \geq 0) の位の数は、A,BA, B を二進表記した際の 2k2^k の位の数のうち一方のみが 11 であれば 11、そうでなければ 00 である。
例えば、35=63 \oplus 5 = 6 となります (二進表記すると: 011101=110011 \oplus 101 = 110)。

制約

  • 1Q3×1051\leq Q \leq 3\times 10^5
  • 0x<2300\leq x < 2 ^{30}
  • クエリ 22 が与えられるとき、黒板に xx が一つ以上書かれている
  • クエリ 33 が与えられるとき、黒板に整数が二つ以上書かれている
  • 入力される数値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

QQ
query1\mathrm{query}_1
query2\mathrm{query}_2
\vdots
queryQ\mathrm{query}_Q

ii 番目のクエリ queryi\mathrm{query}_i では、まずクエリの種類 cic_i1,2,31, 2, 3 のいずれか)が与えられる。 ci=1,ci=2c_i = 1, c_i = 2 の場合はさらに整数 xx が追加で与えられる。

すなわち、各クエリは以下に示す 33 つの形式のいずれかである。

11 xx
22 xx
33

出力

ci=3c_i=3 を満たすクエリの回数を qq として qq 行出力せよ。

j (1jq)j\ (1\leq j\leq q) 行目では jj 番目のそのようなクエリに対する答えを出力せよ。


入力例 1Copy

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

出力例 1Copy

Copy
8
1
9
0

11 番目のクエリ処理後、黒板には 22 が一つ書かれています。

22 番目のクエリ処理後、黒板には 2,102,10 が一つずつ書かれています。

33 番目のクエリ処理時、黒板に書かれた二つの数のビット単位 XOR として考えられる最小値は 210=82\oplus 10=8 です。

44 番目のクエリ処理後、黒板には 2,3,102,3,10 が一つずつ書かれています。

55 番目のクエリ処理時、黒板に書かれた二つの数のビット単位 XOR として考えられる最小値は 23=12\oplus 3=1 です。

66 番目のクエリ処理後、黒板には 3,103,10 が一つずつ書かれています。

77 番目のクエリ処理時、黒板に書かれた二つの数のビット単位 XOR として考えられる最小値は 310=93\oplus 10=9 です。

88 番目のクエリ処理後、黒板には 33 が一つ、 1010 が二つ書かれています。

99 番目のクエリ処理時、黒板に書かれた二つの数のビット単位 XOR として考えられる最小値は 1010=010\oplus 10=0 です。

Score : 600600 points

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 1Copy

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

Sample Output 1Copy

Copy
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.



2025-03-14 (Fri)
16:53:07 +00:00