题解:

比较水吧

显然是平衡树的操作

然后就是写写写

用对拍来查错相比之下直接样例查还是比较容易的

刚开始没有优化常数没开O2就变成暴力分了smg 开了O2就a了

代码:

#include <bits/stdc++.h>
using namespace std;
#define rint register int
#define IL inline
#define rep(i,h,t) for (rint i=h;i<=t;i++)
#define dep(i,t,h) for (rint i=t;i>=h;i--)
#define ll long long
const int N=3e5;
int a[N],rt,x1,x2;
char ss[<<],*A=ss,*B=ss;
IL char gc()
{
return A==B&&(B=(A=ss)+fread(ss,,<<,stdin),A==B)?EOF:*A++;
}
template<class T>void read(T &x)
{
rint f=,c; while (c=gc(),c<||c>) if (c=='-') f=-; x=(c^);
while (c=gc(),c>&&c<) x=(x<<)+(x<<)+(c^); x*=f;
}
struct sgt{
int v[N][],data[N],lazy[N],ls[N],rs[N],count2[N],fa[N];
bool rev[N];
IL void updata(rint x)
{
count2[x]=count2[ls[x]]+count2[rs[x]]+;
rint *a=v[x],*b=v[ls[x]],*c=v[rs[x]],d=data[x];
rep(i,,) a[i]=((d>>i)&)+b[i]+c[i];
// rep(i,0,20) v[x][i]=((data[x]>>i)&1)+v[ls[x]][i]+v[rs[x]][i];
}
IL void down(rint x)
{
if (rev[x])
{
rev[ls[x]]^=; rev[rs[x]]^=;
swap(ls[x],rs[x]);
rev[x]=;
}
if (lazy[x])
{
if (ls[x])
{
lazy[ls[x]]^=lazy[x]; data[ls[x]]^=lazy[x];
dep(i,,)
if ((lazy[x]>>i)&) v[ls[x]][i]=count2[ls[x]]-v[ls[x]][i];
}
if (rs[x])
{
lazy[rs[x]]^=lazy[x]; data[rs[x]]^=lazy[x];
dep(i,,)
if ((lazy[x]>>i)&) v[rs[x]][i]=count2[rs[x]]-v[rs[x]][i];
}
lazy[x]=;
}
}
void rotate(rint x,rint y)
{
rint f1=fa[x];
if (y==)
{
rs[f1]=ls[x];
if (ls[x]) fa[ls[x]]=f1;
} else
{
ls[f1]=rs[x];
if (rs[x]) fa[rs[x]]=f1;
}
fa[x]=fa[f1];
if (fa[f1])
if (ls[fa[f1]]==f1) ls[fa[f1]]=x;
else rs[fa[f1]]=x;
fa[f1]=x;
if (y==) ls[x]=f1; else rs[x]=f1;
updata(f1); updata(x);
}
void dfs(int x)
{
if (fa[x]) dfs(fa[x]);
down(x);
}
void splay(rint x,rint y)
{
dfs(x);
rint f1=fa[x];
while (f1!=y)
{
if (fa[f1]==y)
if (ls[f1]==x) rotate(x,); else rotate(x,);
else
if (ls[fa[f1]]==f1)
if (ls[f1]==x) rotate(f1,),rotate(x,);
else rotate(x,),rotate(x,);
else if (rs[f1]==x) rotate(f1,),rotate(x,);
else rotate(x,),rotate(x,);
f1=fa[x];
}
if (!y) rt=x;
}
IL int search(rint x)
{
rint y=rt;
while (y)
{
down(y);
if (count2[ls[y]]+==x) return(y);
if (count2[ls[y]]>=x) y=ls[y];
else x-=count2[ls[y]]+,y=rs[y];
}
}
IL void split(rint x,rint y)
{
x1=search(x);
x2=search(y);
splay(x2,);
splay(x1,x2);
down(x2); down(x1); x1=rs[x1];
}
}S;
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
int n,m;
read(n); read(m);
rep(i,,n) read(a[i]);
rep(i,,n+)
{
S.rs[i]=i+,S.count2[i]=,S.fa[i+]=i,S.data[i]=a[i-];
}
S.splay(n+,);
rep(i,,m)
{
int kk,x,y,z;
read(kk); read(x); read(y);
if (kk==)
{
S.split(x,y+);
S.rev[x1]^=;
S.splay(x1,);
}
if (kk==)
{
read(z);
S.split(x,y+);
S.lazy[x1]^=z;
S.data[x1]^=z;
rep(i,,) if ((z>>i)&) S.v[x1][i]=S.count2[x1]-S.v[x1][i];
S.splay(x1,);
}
if (kk==)
{
S.split(x,y+);
ll ans=;
dep(i,,) ans+=1ll*(<<i)*S.v[x1][i];
cout<<ans<<endl;
}
}
return ;
}
05-06 07:56