CF817E.Choosing The Commander
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.
Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors.
Each warrior is represented by his personality — an integer number p__i. Each commander has two characteristics — his personality p__j and leadership l__j (both are integer numbers). Warrior i respects commander j only if
(
is the bitwise excluding OR of x and y).
Initially Vova's army is empty. There are three different types of events that can happen with the army:
- 1 p__i — one warrior with personality p__i joins Vova's army;
- 2 p__i — one warrior with personality p__i leaves Vova's army;
- 3 p__i l__i — Vova tries to hire a commander with personality p__i and leadership l__i.
For each event of the third type Vova wants to know how many warriors (counting only those who joined the army and haven't left yet) respect the commander he tries to hire.
如你可能从上一轮题目中记得的那样,沃瓦(Vova)当前正在玩一款名为《帝国之怒》(Rage of Empires)的战略游戏。
沃瓦成功组建了一支庞大的军队,却忘记了军队中最关键的人物——指挥官。因此,他试图聘请一名指挥官,并希望选择一位能受到战士们尊敬的人。
每位战士由其个性——一个整数 pi 表示;每位指挥官具有两个属性:其个性 pj 和领导力 lj(二者均为整数)。战士 i 尊敬指挥官 j 当且仅当

(其中
表示 x 与 y 的按位异或运算)。
初始时,沃瓦的军队为空。军队中可能发生三种不同类型的事件:
1 p_i—— 一名个性为 pi 的战士加入沃瓦的军队;2 p_i—— 一名个性为 pi 的战士离开沃瓦的军队;3 p_i l_i—— 沃瓦尝试聘请一名个性为 pi、领导力为 li 的指挥官。
对于每一类第三种事件,沃瓦希望知道:当前军队中(即已加入且尚未离开的战士)有多少名战士尊敬他正尝试聘请的这位指挥官。
输入格式
The first line contains one integer q (1 ≤ q ≤ 100000) — the number of events.
Then q lines follow. Each line describes the event:
- 1 p__i (1 ≤ p__i ≤ 108) — one warrior with personality p__i joins Vova's army;
- 2 p__i (1 ≤ p__i ≤ 108) — one warrior with personality p__i leaves Vova's army (it is guaranteed that there is at least one such warrior in Vova's army by this moment);
- 3 p__i l__i (1 ≤ p__i, l__i ≤ 108) — Vova tries to hire a commander with personality p__i and leadership l__i. There is at least one event of this type.
第一行包含一个整数 q(1≤q≤100000)——事件的数量。
接下来是 q 行,每行描述一个事件:
1 p_i(1≤pi≤108)——一名性格值为 pi 的战士加入沃瓦的军队;2 p_i(1≤pi≤108)——一名性格值为 pi 的战士离开沃瓦的军队(保证此时沃瓦的军队中至少存在一名性格值为 pi 的战士);3 p_i l_i(1≤pi,li≤108)——沃瓦尝试招募一名性格值为 pi、领导力为 li 的指挥官。至少存在一个此类事件。
输出格式
For each event of the third type print one integer — the number of warriors who respect the commander Vova tries to hire in the event.
对于每个第三类事件,输出一个整数——即尊重 Vova 尝试在该事件中招募的指挥官的战士人数。
输入输出样例
输入#1
5 1 3 1 4 3 6 3 2 4 3 6 3
输出#1
1 0
说明/提示
In the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him (
, and 2 < 3, but
, and 5 ≥ 3). Then warrior with personality 4 leaves, and when Vova tries to hire that commander again, there are no warriors who respect him.
在示例中,经过前两次事件后,军队由两名个性值分别为 3 和 4 的战士组成。接着,沃瓦尝试招募一名个性值为 6、领导力为 3 的指挥官,此时仅有一名战士尊重他(
,且 2 < 3;但
,且 5 ≥ 3)。随后,个性值为 4 的战士离开。当沃瓦再次尝试招募该指挥官时,已无任何战士尊重他。
输入解题思路,AI测评打分。不知道怎么写?