CF1515H.Phoenix and Bits

普及/提高-

通过率:0%

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 lairl \le a_i \le r with aia_i AND xx ;
  2. replace all numbers aia_i where lairl \le a_i \le r with aia_i OR xx ;
  3. replace all numbers aia_i where lairl \le a_i \le r with aia_i XOR xx ;
  4. output how many distinct integers aia_i where lairl \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.

输入格式

The first line contains two integers nn and qq ( 1n21051 \le n \le 2 \cdot 10^5 ; 1q1051 \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 ( 0ai<2200 \le a_i < 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 ( 1t41 \le t \le 4 ) — the type of query.

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

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

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

输出格式

Print the answer for each query where 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 .
首页