luogu#P11160. 【MX-X6-T6】機械生命体

【MX-X6-T6】機械生命体

Background

Original link: https://oier.team/problems/X6G


Please forgive me, already\\ Understand it\\ The true form of this place\\ Even I cannot\\ Love myself\\ Give me the price for having feelings\\ I am going crazy

—— Mechanical Lifeform - Nanatsukaze

Can binary operations and memory bring back human emotions in a mechanical lifeform?

Problem Description

Maintain a multiset SS, initially empty. It supports the following operations:

  • 1 x: Insert a number xx into SS.
  • 2 x: Delete a number xx from SS. It is guaranteed that at this time SS contains at least one xx. If there are multiple xx, delete only one.
  • 3 x k v: For all yy in SS that satisfy lowbit(xy)2k\operatorname{lowbit}(x\oplus y)\geq 2^k, increase yy by vv and take modulo 2322^{32}.
  • 4 x: Query $\max\limits_{y\in S} \operatorname{lowbit}(x\oplus y)$. It is guaranteed that at this time SS is not empty.

Here, lowbit(x)\operatorname{lowbit}(x) denotes the largest integer kk such that kk is an integer power of 22 and divides xx. \oplus denotes bitwise XOR

In particular, in this problem we define lowbit(0)=232\boldsymbol{\textbf{lowbit}(0)=2^{32}}.

Input Format

The first line contains an integer qq, the number of queries.

Then follow qq lines. Each line first contains an integer optopt indicating the operation type. If opt=3opt=3, then three integers x,k,vx,k,v follow in order; otherwise, one integer xx follows.

Output Format

For each operation 4, output one integer representing the answer.

11
1 1
1 2
1 2
1 3
1 4
4 10
3 2 1 2
2 4
4 16
2 4
4 16
8
4
2

Hint

Sample Explanation.

At the 6th operation, the multiset is {1,2,2,3,4}\{1,2,2,3,4\}. When querying 1010, $\operatorname{lowbit}(10\oplus 2)=\operatorname{lowbit}(8)=8$ is the maximum.

After the 7th operation, all numbers with lowbit(x2)21\operatorname{lowbit}(x\oplus 2)\geq 2^1 are increased by 22. The numbers in the multiset that satisfy the condition are 2,2,42,2,4, so the multiset becomes {1,3,4,4,6}\{1,3,4,4,6\}.

At the 8th operation, one 44 is deleted, and the multiset becomes {1,3,4,6}\{1,3,4,6\}.

At the 9th operation, query 1616. $\operatorname{lowbit}(16\oplus 4)=\operatorname{lowbit}(20)=4$ is the maximum.

At the 10th operation, one 44 is deleted again, and the multiset becomes {1,3,6}\{1,3,6\}.

At the 11th operation, query 1616. $\operatorname{lowbit}(16\oplus 6)=\operatorname{lowbit}(22)=2$ is the maximum.

Constraints.

For all testdata, 1q5×1051\leq q\leq 5\times 10^5, 0x,y,v23210\leq x,y,v\leq 2^{32}-1, 0k320\leq k\leq 32.

Bundled tests, a total of 5 subtasks, with the specific limits as follows:

  • Subtask 1 (7 pts): q103q\leq 10^3.
  • Subtask 2 (16 pts): There is no operation 3.
  • Subtask 3 (21 pts): For operation 3, k=0k=0.
  • Subtask 4 (28 pts): For operation 3, v=1v=1.
  • Subtask 5 (28 pts): No special constraints.

Translated by ChatGPT 5