全 WA 求助
查看原帖
全 WA 求助
986683
_Ponder_楼主2023/6/23 16:07

rt,思路和第二篇题解一样,但不知道为什么全 WA 了。

#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;
const int N=50100,M=32,L=34;
#define mid (a[p].l+a[p].r>>1)

int n,m,in1,in2,in3,op;
int inp[N],inp2[N];

struct Hamel{
    int a[L];
    void init(){memset(a,0,sizeof a);}
    void insert(int x){
        for(int i=M;i>=0;i--)
            if(x>>i&1)
                if(!a[i]){a[i]=x;return ;}
                else x^=a[i];
    }
    int ask(int x){
        for(int i=M;i>=0;i--)
            x=max(x,x^a[i]);
        return x;
    }
};

struct STn{
    int l,r,val;
    Hamel h;
};
STn operator +(STn a,STn b){
    STn c;
    c.l=a.l;c.r=b.r;c.val=a.val^b.val;c.h=a.h;
    for(int i=M;i>=0;i--) c.h.insert(b.h.a[i]);
    return c;
}
struct ST{
    STn a[N<<2];
    void build(int p,int l,int r){
        a[p].l=l;a[p].r=r;
        if(a[p].l==a[p].r){a[p].h.insert(a[p].val=inp2[a[p].l]);return ;}
        build(p<<1,l,mid);build(p<<1|1,mid+1,r);
        a[p]=a[p<<1]+a[p<<1|1];
    }
    STn ask(int p,int l,int r){
        if(l<=a[p].l&&a[p].r<=r) return a[p];
        if(r<=mid) return ask(p<<1,l,r);
        if(l>mid) return ask(p<<1|1,l,r);
        return ask(p<<1,l,r)+ask(p<<1|1,l,r);
    }
    void change(int p,int x,int k){
        if(a[p].l==a[p].r){a[p].h.init();a[p].h.insert(a[p].val^=k);return ;}
        if(x<=mid) change(p<<1,x,k);
        else change(p<<1|1,x,k);
        a[p]=a[p<<1]+a[p<<1|1];
    }
}tree;

int main(){
    freopen("the.in","r",stdin);
    freopen("the.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&inp[i]);
    for(int i=1;i<=n;i++) inp2[i]=inp[i-1]^inp[i];
    tree.build(1,1,n);
    while(m--){
        scanf("%d%d%d%d",&op,&in1,&in2,&in3);
        if(op==1){
            tree.change(1,in1,in3);
            if(in2<n) tree.change(1,in2+1,in3);
        }
        if(op==2){
            int val=tree.ask(1,1,in1).val;
            if(in1==in2){cout<<max(in3,in3^val)<<'\n';continue;}
            STn res=tree.ask(1,in1+1,in2);
            res.h.insert(val);
            cout<<res.h.ask(in3)<<'\n';
        }
    }
    return 0;
}
2023/6/23 16:07
加载中...