1515_H. Phoenix and Bits

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

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



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

Input

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

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ 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 ≤ t ≤ 4) — the type of query.

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

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

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

Output

Print the answer for each query where t=4.

Examples

Input


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


Output


3
2
1


Input


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


Output


5
1
2

Note

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. 

Example input:
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

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


Example output:

5
1
2


3
2
1


Tags: bitmasks
brute force
data structures
sortings
Difficulty rating: 3500

Solution:
#include<bits/stdc++.h>
#define lson ls[x],l,mid
#define rson rs[x],mid+1,r
using namespace std;const int N=2e5+7,M=N*50;
int rt,rt1,x,n,m,i,j,l,r,t,tk[M],ls[M],rs[M],ts[M],ts0[M],ts1[M],U,tag[M],sz;
void ud(int x){ts[x]=ts[ls[x]]+ts[rs[x]];ts0[x]=ts0[ls[x]]|ts0[rs[x]];ts1[x]=ts1[ls[x]]|ts1[rs[x]];}
int newnode(int k){return tk[sz+1]=k,++sz;}
void A(int x,int val){
	if(!x)return;
	tag[x]^=val;if(~tk[x]&&val>>tk[x]&1)swap(ls[x],rs[x]);
	int X=(ts0[x]&(U^val))|(ts1[x]&val),Y=(ts1[x]&(U^val))|(ts0[x]&val);
	ts0[x]=X;ts1[x]=Y;
}
void pd(int x){if(tag[x])A(ls[x],tag[x]),A(rs[x],tag[x]),tag[x]=0;}
void ins(int&x,int l,int r,int pos,int k){
	if(!x)x=newnode(k);if(l==r){ts[x]=1;ts0[x]=U^pos;ts1[x]=U&pos;return;}int mid=l+r>>1;
	if(pos<=mid)ins(lson,pos,k-1);else ins(rson,pos,k-1);ud(x);
}
int merge(int x,int y){
	if(x==0||y==0)return x+y;pd(x);pd(y);
	ls[x]=merge(ls[x],ls[y]);rs[x]=merge(rs[x],rs[y]);
	if(~tk[x])ud(x);return x;
}
void split(int&x,int l,int r,int&y,int a,int b){
	if(!x||a<=l&&r<=b){y=x;x=0;return;}int mid=l+r>>1;y=newnode(tk[x]);pd(x);
	if(a<=mid)split(lson,ls[y],a,b);if(b>mid)split(rson,rs[y],a,b);ud(y);ud(x);
}
void modify(int x,int val){
	if(!x)return;
	if(!(val&ts0[x]&ts1[x]))return A(x,val&ts0[x]);pd(x);int k=tk[x];
	if((val>>k&1))A(ls[x],1<<k),rs[x]=merge(rs[x],ls[x]),ls[x]=0;
	modify(ls[x],val),modify(rs[x],val);if(k>=0)ud(x);
}
int main(){
	for(scanf("%d%d",&n,&m),U=(1<<20)-1,i=1;i<=n;++i)scanf("%d",&j),ins(rt,0,U,j,19);
	for(;m--;){
		scanf("%d%d%d",&t,&l,&r);split(rt,0,U,rt1,l,r);
		if(t==1)scanf("%d",&x),A(rt1,U),modify(rt1,x^U),A(rt1,U);
		if(t==2)scanf("%d",&x),modify(rt1,x);
		if(t==3)scanf("%d",&x),A(rt1,x);
		if(t==4)printf("%d\n",ts[rt1]);
		rt=merge(rt,rt1);
	}
}