CF1515H.Phoenix and Bits
NOI/NOI+/CTSC
通过率:0%
时间限制:4.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Phoenix loves playing with bits — specifically, by using the bitwise operations AND, OR, and XOR. He has n integers a1,a2,…,an, and will perform q of the following queries:
- replace all numbers ai where l≤ai≤r with ai AND x;
- replace all numbers ai where l≤ai≤r with ai OR x;
- replace all numbers ai where l≤ai≤r with ai XOR x;
- output how many distinct integers ai where l≤ai≤r.
For each query, Phoenix is given l, r, and x. Note that he is considering the values of the numbers, not their indices.
凤凰喜欢玩位运算——特别是使用按位与(AND)、按位或(OR)和按位异或(XOR)。他有 n 个整数 a1,a2,…,an,并将执行 q 个如下查询:
- 将所有满足 l≤ai≤r 的数 ai 替换为 ai AND x;
- 将所有满足 l≤ai≤r 的数 ai 替换为 ai OR x;
- 将所有满足 l≤ai≤r 的数 ai 替换为 ai XOR x;
- 输出满足 l≤ai≤r 的不同整数 ai 的个数。
对于每个查询,凤凰会得到参数 l、r 和 x。注意,他考虑的是数值本身,而非其下标。
输入格式
The first line contains two integers n and q (1≤n≤2⋅105; 1≤q≤105) — the number of integers and the number of queries, respectively.
The second line contains n integers a1,a2,…,an (0≤ai<220) — the integers that Phoenix starts with.
The next q lines contain the queries. For each query, the first integer of each line is t (1≤t≤4) — the type of query.
If t∈1,2,3, then three integers li, ri, and xi will follow (0≤li,ri,xi<220; li≤ri).
Otherwise, if t=4, two integers li and ri will follow (0≤li≤ri<220).
It is guaranteed that there is at least one query where t=4.
第一行包含两个整数 n 和 q(1≤n≤2⋅105;1≤q≤105)—— 分别表示整数的个数和查询的个数。
第二行包含 n 个整数 a1,a2,…,an(0≤ai<220)—— Phoenix 初始拥有的整数。
接下来 q 行为查询。对每个查询,每行的第一个整数为 t(1≤t≤4)—— 查询类型。
若 t∈{1,2,3},则随后将给出三个整数 li、ri 和 xi(0≤li,ri,xi<220;li≤ri)。
否则,若 t=4,则随后将给出两个整数 li 和 ri(0≤li≤ri<220)。
保证至少存在一个满足 t=4 的查询。
输出格式
Print the answer for each query where t=4.
对每个满足 t=4 的查询,输出答案。
输入输出样例
输入#1
5 6 5 4 3 2 1 1 2 3 2 4 2 5 3 2 5 3 4 1 6 2 1 1 8 4 8 10
输出#1
3 2 1
输入#2
6 7 6 0 2 3 2 7 1 0 4 3 2 6 8 4 4 0 7 3 2 5 3 1 0 1 2 4 0 3 4 2 7
输出#2
5 1 2
说明/提示
In the first example:
- For the first query, 2 is replaced by 2 AND 2=2 and 3 is replaced with 3 AND 2=2. The set of numbers is 1,2,4,5.
- For the second query, there are 3 distinct numbers between 2 and 5: 2, 4, and 5.
- For the third query, 2 is replaced by 2 XOR 3=1, 4 is replaced by 4 XOR 3=7, and 5 is replaced by 5 XOR 3=6. The set of numbers is 1,6,7.
- For the fourth query, there are 2 distinct numbers between 1 and 6: 1 and 6.
- For the fifth query, 1 is replaced by 1 OR 8=9. The set of numbers is 6,7,9.
- For the sixth query, there is one distinct number between 8 and 10: 9.
在第一个样例中:
- 对于第一个查询,2 被替换为 2 AND 2=2,3 被替换为 3 AND 2=2。此时数字集合为 1,2,4,5。
- 对于第二个查询,在 2 到 5 之间有 3 个不同的数:2、4 和 5。
- 对于第三个查询,2 被替换为 2 XOR 3=1,4 被替换为 4 XOR 3=7,5 被替换为 5 XOR 3=6。此时数字集合为 1,6,7。
- 对于第四个查询,在 1 到 6 之间有 2 个不同的数:1 和 6。
- 对于第五个查询,1 被替换为 1 OR 8=9。此时数字集合为 6,7,9。
- 对于第六个查询,在 8 到 10 之间有 1 个不同的数:9。
输入解题思路,AI测评打分。不知道怎么写?