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 nn integers a1,a2,…,ana_1, a_2, \dots, a_n, and will perform qq of the following queries:

  1. replace all numbers aia_i where l≤ai≤rl \le a_i \le r with aia_i AND xx;
  2. replace all numbers aia_i where l≤ai≤rl \le a_i \le r with aia_i OR xx;
  3. replace all numbers aia_i where l≤ai≤rl \le a_i \le r with aia_i XOR xx;
  4. output how many distinct integers aia_i where l≤ai≤rl \le a_i \le r.

For each query, Phoenix is given ll, rr, and xx. Note that he is considering the values of the numbers, not their indices.

凤凰喜欢玩位运算——特别是使用按位与(AND)、按位或(OR)和按位异或(XOR)。他有 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n,并将执行 qq 个如下查询:

  1. 将所有满足 l≤ai≤rl \le a_i \le r 的数 aia_i 替换为 aia_i AND xx;
  2. 将所有满足 l≤ai≤rl \le a_i \le r 的数 aia_i 替换为 aia_i OR xx;
  3. 将所有满足 l≤ai≤rl \le a_i \le r 的数 aia_i 替换为 aia_i XOR xx;
  4. 输出满足 l≤ai≤rl \le a_i \le r 的不同整数 aia_i 的个数。

对于每个查询,凤凰会得到参数 ll、rr 和 xx。注意,他考虑的是数值本身,而非其下标。

输入格式

The first line contains two integers nn and qq (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 1≤q≤1051 \le q \le 10^5) — the number of integers and the number of queries, respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai<2200 \le a_i \lt 2^{20}) — the integers that Phoenix starts with.

The next qq lines contain the queries. For each query, the first integer of each line is tt (1≤t≤41 \le t \le 4) — the type of query.

If t∈1,2,3t \in {1, 2, 3}, then three integers lil_i, rir_i, and xix_i will follow (0≤li,ri,xi<2200 \le l_i, r_i, x_i \lt 2^{20}; li≤ril_i \le r_i).

Otherwise, if t=4t=4, two integers lil_i and rir_i will follow (0≤li≤ri<2200 \le l_i \le r_i \lt 2^{20}).

It is guaranteed that there is at least one query where t=4t=4.

第一行包含两个整数 nn 和 qq(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;1≤q≤1051 \le q \le 10^5)—— 分别表示整数的个数和查询的个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai<2200 \le a_i \lt 2^{20})—— Phoenix 初始拥有的整数。

接下来 qq 行为查询。对每个查询,每行的第一个整数为 tt(1≤t≤41 \le t \le 4)—— 查询类型。

若 t∈{1,2,3}t \in \{1, 2, 3\},则随后将给出三个整数 lil_i、rir_i 和 xix_i(0≤li,ri,xi<2200 \le l_i, r_i, x_i \lt 2^{20};li≤ril_i \le r_i)。

否则,若 t=4t = 4,则随后将给出两个整数 lil_i 和 rir_i(0≤li≤ri<2200 \le l_i \le r_i \lt 2^{20})。

保证至少存在一个满足 t=4t = 4 的查询。

输出格式

Print the answer for each query where t=4t=4.

对每个满足 t=4t=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, 22 is replaced by 22 AND 2=22 = 2 and 33 is replaced with 33 AND 2=22 = 2. The set of numbers is 1,2,4,5{1, 2, 4, 5}.
  • For the second query, there are 33 distinct numbers between 22 and 55: 22, 44, and 55.
  • For the third query, 22 is replaced by 22 XOR 3=13 = 1, 44 is replaced by 44 XOR 3=73 = 7, and 55 is replaced by 55 XOR 3=63 = 6. The set of numbers is 1,6,7{1, 6, 7}.
  • For the fourth query, there are 22 distinct numbers between 11 and 66: 11 and 66.
  • For the fifth query, 11 is replaced by 11 OR 8=98 = 9. The set of numbers is 6,7,9{6, 7, 9}.
  • For the sixth query, there is one distinct number between 88 and 1010: 99.

在第一个样例中:

  • 对于第一个查询,22 被替换为 22 AND 2=22 = 2,33 被替换为 33 AND 2=22 = 2。此时数字集合为 1,2,4,5{1, 2, 4, 5}。
  • 对于第二个查询,在 22 到 55 之间有 33 个不同的数:22、44 和 55。
  • 对于第三个查询,22 被替换为 22 XOR 3=13 = 1,44 被替换为 44 XOR 3=73 = 7,55 被替换为 55 XOR 3=63 = 6。此时数字集合为 1,6,7{1, 6, 7}。
  • 对于第四个查询,在 11 到 66 之间有 22 个不同的数:11 和 66。
  • 对于第五个查询,11 被替换为 11 OR 8=98 = 9。此时数字集合为 6,7,9{6, 7, 9}。
  • 对于第六个查询,在 88 到 1010 之间有 11 个不同的数:99。

输入解题思路,AI测评打分。不知道怎么写?

首页