96分,最后一个点RE求助
查看原帖
96分,最后一个点RE求助
275673
Coutti楼主2022/8/1 17:08
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
//#include<windows.h>
//#include<ctime>
using namespace std;
int rt[350100],ct,n,v,op,l,r;
long long la;
struct node
{
	int lc,rc,lz,sz,vl;
	long long s;
}t[20000400];
inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return f==1?x:-x;
}
void psu(int p)
{
	t[p].sz=t[t[p].lc].sz+t[t[p].rc].sz+1;
	t[p].s=t[t[p].lc].s+t[t[p].rc].s+t[p].vl;
}
void psd(int p)
{
	if(!t[p].lz)
	  return;
	int xx=++ct,yy=++ct;
	t[xx]=t[t[p].lc];
	t[yy]=t[t[p].rc];
	if(t[p].lc)
	{
		t[p].lc=xx;
		t[t[p].lc].lz^=1;
	}
	if(t[p].rc)
	{
		t[p].rc=yy;
		t[t[p].rc].lz^=1;
	} 
	swap(t[p].lc,t[p].rc);
	t[p].lz^=1;
}
int nnd(int v)
{
	t[++ct].sz=1;
	t[ct].vl=t[ct].s=v;
	return ct; 
}
int merge(int aa,int bb)
{
	if(!aa||!bb)
	  return aa+bb;
	psd(aa);
	psd(bb);
	int p=++ct;
	if(t[aa].sz>t[bb].sz)
	{
		t[p]=t[aa];
		t[p].rc=merge(t[p].rc,bb);
	}
	else
	{
		t[p]=t[bb];
		t[p].lc=merge(aa,t[p].lc);
	}
	psu(p);
	return p;
}
void spt(int p,int k,int &x,int &y)
{
	if(!p)
	{
		x=0;
		y=0;
		return;
	}
	psd(p);
	if(t[t[p].lc].sz+1<=k)
	{
		x=++ct;
		t[x]=t[p];
		spt(t[p].rc,k-t[t[p].lc].sz-1,t[x].rc,y);
		psu(x);
	}
	else
	{
		y=++ct;
		t[y]=t[p];
		spt(t[p].lc,k,x,t[y].lc);
		psu(y);
  }
}
void ins(int &rot,int p,int v)
{
	static int xx,yy;
	spt(rot,p,xx,yy);
	rot=merge(merge(xx,nnd(v)),yy);
}
void del(int &rot,int p)
{
	static int xx,yy,zz;
	spt(rot,p,xx,zz);
	spt(xx,p-1,xx,yy);
	rot=merge(xx,zz);
}
void rev(int &rot,int ll,int rr)
{
	static int xx,yy,zz;
	spt(rot,rr,xx,zz);
	spt(xx,ll-1,xx,yy);
	t[yy].lz^=1;
	rot=merge(merge(xx,yy),zz);
}
long long gsm(int &rot,int ll,int rr)
{
	static int xx,yy,zz;
	static long long re;
	spt(rot,rr,xx,zz);
	spt(xx,ll-1,xx,yy);
	re=t[yy].s;
	rot=merge(merge(xx,yy),zz);
	return re;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		v=read();
		op=read();
		l=read()^la;
		if(op!=2)
		  r=read()^la;
		rt[i]=rt[v];
		if(op==1)
		  ins(rt[i],l,r);
		if(op==2)
		  del(rt[i],l);
		if(op==3)
		  rev(rt[i],l,r);
		if(op==4)
		  cout<<(la=gsm(rt[i],l,r))<<endl;
	}
	return 0;
}
2022/8/1 17:08
加载中...