题库练习 Phoenix and Bits
← 上一题 下一题 →

A14198 | Phoenix and Bits

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Phoenix loves playing with bits — specifically, by using the bitwise operations AND, OR, and XOR. He has $n$ integers $a_1, a_2, \dots, a_n$ , and will perform $q$ of the following queries:

1. replace all numbers $a_i$ where $l \le a_i \le r$ with $a_i$ AND $x$ ;
2. replace all numbers $a_i$ where $l \le a_i \le r$ with $a_i$ OR $x$ ;
3. replace all numbers $a_i$ where $l \le a_i \le r$ with $a_i$ XOR $x$ ;
4. output how many distinct integers $a_i$ where $l \le a_i \le r$ .

For each query, Phoenix is given $l$ , $r$ , and $x$ . Note that he is considering the values of the numbers, not their indices.

输入格式

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

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 \le a_i < 2^{20}$ ) — 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 \le t \le 4$ ) — the type of query.

If $t \in \{1, 2, 3\}$ , then three integers $l_i$ , $r_i$ , and $x_i$ will follow ( $0 \le l_i, r_i, x_i < 2^{20}$ ; $l_i \le r_i$ ).

Otherwise, if $t=4$ , two integers $l_i$ and $r_i$ will follow ( $0 \le l_i \le r_i < 2^{20}$ ).

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

输出格式

Print the answer for each query where $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
C++ 编辑器
输入
输出