​传送门​

我们按每一位贪心, 在主席树中找存不存在对异或有贡献的数就可以了

#include<bits/stdc++.h>
#define N 200050
using namespace std;
int read(){
int cnt=0,f=1;char ch=0;
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))cnt=cnt*10+(ch-'0'),ch=getchar();
return cnt*f;
}
struct Node{int ls,rs,val;}t[N*40];
int rt[N],tot,n,m,Max,a[N];
void Build(int &x,int l,int r){
x = ++tot;
if(l==r) return;
int mid = (l+r) >> 1;
Build(t[x].ls, l, mid);
Build(t[x].rs, mid+1, r);
}
void Insert(int &x,int last,int l,int r,int pos){
x = ++tot; t[x] = t[last]; t[x].val++;
if(l==r) return;
int mid = (l+r) >> 1;
if(pos<=mid) Insert(t[x].ls, t[last].ls, l, mid, pos);
else Insert(t[x].rs, t[last].rs, mid+1, r, pos);
}
int Quary(int a,int b,int l,int r,int L,int R){
if(L<=l && r<=R) return t[a].val - t[b].val;
int mid = (l+r) >> 1, ans = 0;
if(L<=mid) ans += Quary(t[a].ls, t[b].ls, l, mid, L, R);
if(R>mid) ans += Quary(t[a].rs, t[b].rs, mid+1, r, L, R);
return ans;
}
int main(){
n = read(), m = read();
for(int i=1;i<=n;i++){
a[i] = read();
Max = max(a[i], Max);
} Build(rt[0],0,Max);
for(int i=1;i<=n;i++) Insert(rt[i], rt[i-1], 0, Max, a[i]);
while(m--){
int b = read(), x = read(), l = read(), r = read();
int ans = 0;
for(int i=17;i>=0;i--){
int k = (b>>i)&1;
int L = ans + ((k^1)<<i) - x;
int R = L + (1<<i) - 1;
if(L>Max) continue;
if(L<0) L = 0; if(R>Max) R = Max;
if(Quary(rt[r], rt[l-1], 0, Max, L, R)) ans += ((k^1)<<i);
else ans += (k<<i);
} printf("%d\n",ans^b);
} return 0;
}