样例过了,评测0分
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int n,tot;
int root[maxn];
struct sm
{
int child[2];
int rd,size;
int lazy;
long long sum,val;
}t[maxn*100];
int copy(int x)
{
++tot;
t[tot]=t[x];
return tot;
}
int make(long long val)
{
t[++tot].val=val;
t[tot].size=1;
t[tot].sum=val;
t[tot].rd=rand();
return tot;
}
void pushup(int x)
{
t[x].size=t[t[x].child[0]].size+t[t[x].child[1]].size+1;
t[x].sum=t[t[x].child[0]].sum+t[t[x].child[1]].sum+t[x].val;
}
void pushdown(int x)
{
if(t[x].lazy)
{
swap(t[x].child[0],t[x].child[1]);
if(t[x].child[0])t[x].child[0]=copy(t[x].child[0]),t[t[x].child[0]].lazy^=1;
if(t[x].child[1])t[x].child[1]=copy(t[x].child[1]),t[t[x].child[1]].lazy^=1;
t[x].lazy=0;
}
}
void split(int now,long long k,int &x,int &y)
{
if(!now)
{
x=y=0;
return;
}
pushdown(now);
if(k>t[t[now].child[0]].size)
{
x=copy(now);
split(t[x].child[1],k-t[t[x].child[0]].size-1,t[x].child[1],y);
pushup(x);
}
else
{
y=copy(now);
split(t[y].child[0],k,x,t[y].child[0]);
pushup(y);
}
}
int merge(int A,int B)
{
if(!A||!B)return A|B;
if(t[A].rd<t[B].rd)
{
pushdown(A);
t[A].child[1]=merge(t[A].child[1],B);
pushup(A);
return A;
}
else
{
pushdown(B);
t[B].child[0]=merge(t[B].child[0],A);
pushup(B);
return B;
}
}
void insert(int &rt,long long k,long long x)
{
int A=0,B=0;
split(rt,k,A,B);
rt=merge(merge(A,make(x)),B);
}
void delate(int &rt,long long x)
{
int A=0,B=0,C=0;
split(rt,x,A,B);
split(A,x-1,A,C);
rt=merge(A,B);
}
int main()
{
srand(time(0));
long long lastans=0;
scanf("%d",&n);
int opt,v;
long long x,y;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&v,&opt);
root[i]=root[v];
if(opt==1)
{
scanf("%lld%lld",&x,&y);
x^=lastans;
y^=lastans;
insert(root[i],x,y);
}
if(opt==2)
{
scanf("%lld",&x);
x^=lastans;
delate(root[i],x);
}
if(opt==3)
{
scanf("%lld%lld",&x,&y);
x^=lastans;
y^=lastans;
if(x>y)swap(x,y);
int A=0,B=0,C=0;
split(root[i],y,A,B);
split(A,x-1,A,C);
t[C].lazy^=1;
root[i]=merge(A,merge(C,B));
}
if(opt==4)
{
scanf("%lld%lld",&x,&y);
x^=lastans;
y^=lastans;
if(x>y)swap(x,y);
int A=0,B=0,C=0;
split(root[i],y,A,B);
split(A,x-1,A,C);
lastans=t[C].sum;
printf("%lld\n",lastans);
root[i]=merge(A,(merge(C,B)));
}
}
return 0;
}