1 . " %f " " %lf "注意切换。
2. 结构体排序问题,记得 记录 id 操作完后根据题目要求看是否需要按照 id 恢复。
3. dp [ ] [ ] 转移时,有时候一个 dp [ i ] [ j ]可能由多个状态转移而来,不要直接赋值,而是累加。
#include<bits/stdc++.h> using namespace std; #define maxn 13245 int t,n,q,k,a[maxn],rk,l,r,ans; struct node { int p[33]; void init() { memset(p,0,sizeof(p)); } void add(int x) { for(int i=30; i>=0; i--) { if(!(x>>i))continue; if(!p[i]) { p[i]=x; break; } x^=p[i]; } } node operator + (const node &b)const { node ret=*this; for(int i=30; i>=0; i--) if(b.p[i])ret.add(b.p[i]); return ret; } int cp() { int re=0; for(int i=30; i>=0; i--) if(re^p[i]>=re)re^=p[i]; return re; } } tree[maxn*4]; void up(int root) { tree[root]=tree[root*2]+tree[root*2+1]; } void bulid(int root,int l,int r) { tree[root].init(); if(l==r) { tree[root].add(a[l]); return ; } int mid=(l+r)/2; bulid(root*2,l,mid); bulid(root*2+1,mid+1,r); up(root); } node query(int root,int l,int r,int L,int R) { if(L<=l&&r<=R) return tree[root]; int mid=(l+r)/2; if(L>mid) return query(root*2+1,mid+1,r,L,R); else if(R<=mid)return query(root*2,l,mid,L,R); else return (query(root*2,l,mid,L,R)+query(root*2+1,mid+1,r,L,R)); } int main() { scanf("%d",&t); while(t--) { rk=0; scanf("%d%d%d",&n,&q,&k); for(int i=30; i>=0; i--) if(!(k>>i))rk|=(1<<i); for(int i=1; i<=n; i++) { scanf("%d",&a[i]); a[i]=a[i]&rk; } bulid(1,1,n); while(q--) { scanf("%d%d",&l,&r); ans=query(1,1,n,l,r).cp(); ans|=k; printf("%d\n",ans); } } return 0; }