离谱错求调教
查看原帖
离谱错求调教
754502
_AyachiNene楼主2024/1/11 17:51

写了两个版本,本地都是对的,交上去错的位置一模一样

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
struct node
{
	int l,r,siz,rnd;
	int val,sum,tag;
}t[30000000];
int cnt;
int root[2000005];
int New(int x)
{
	t[++cnt].val=t[cnt].sum=x;
	t[cnt].rnd=rand();
	t[cnt].siz=1;
	return cnt;
}
void down(int p)
{
	if(t[p].tag)
	{
		if(t[p].l)
			t[++cnt]=t[t[p].l],t[p].l=cnt,t[cnt].tag^=1;
		if(t[p].r)
			t[++cnt]=t[t[p].r],t[p].r=cnt,t[cnt].tag^=1;
		swap(t[p].l,t[p].r);
		t[p].tag=0;
	}
}
void update(int p)
{
	t[p].siz=t[t[p].l].siz+t[t[p].r].siz+1;
	t[p].sum=t[t[p].l].sum+t[t[p].r].sum+t[p].val;	
}
int merge(int x,int y)
{
	if(!x||!y)
		return x|y;
	int cur=++cnt;
	down(x),down(y);
	if(t[x].rnd<t[y].rnd)
	{
		t[cur]=t[x];
		t[cur].r=merge(t[cur].r,y);
	}
	else
	{
		t[cur]=t[y];
		t[cur].l=merge(x,t[cur].l);
	}
	update(cur);
	return cur;
}
void split(int p,int v,int &x,int &y)
{
	if(!p)
		x=y=0;
	else
	{
		down(p);
		if(t[t[p].l].siz+1<=v)
		{
			x=++cnt;
			t[x]=t[p];
			split(t[x].r,v-t[t[p].l].siz-1,t[x].r,y);
			update(x);
		}
		else
		{
			y=++cnt;
			t[y]=t[p];
			split(t[y].l,v,x,t[y].l);
			update(y);
		}
	}
}
void insert(int x,int y,int p,int v)
{
	int a,b;
	split(root[y],p,a,b);
	root[x]=merge(a,merge(New(v),b));
}
void rev(int x,int y,int l,int r)
{
	int a,b,c;
	split(root[y],r,b,c);
	split(b,l-1,a,b);
	t[b].tag^=1;
	root[x]=merge(a,merge(b,c));
}
void del(int x,int y,int p)
{
	int a,b,c;
	split(root[y],p,b,c);
	split(b,p-1,a,b);
	root[x]=merge(a,c);
}
int query(int x,int y,int l,int r)
{
	int a,b,c;
	split(root[y],r,b,c);
	split(b,l-1,a,b);
	int res=t[b].sum;
	root[x]=merge(a,merge(b,c));
	return res;
}
int n;
int ans;
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		int v=read(),op=read(),l=(read()^ans),r;
		if(op!=2)
			r=(read()^ans);
		if(op==1)
			insert(i,v,l,r);
		else if(op==2)
			del(i,v,l);
		else if(op==3)
			rev(i,v,l,r);
		else
			write(ans=query(i,v,l,r)),puts("");
	}
}
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
struct node
{
	int l,r,siz,rnd;
	int val,sum,tag;
}t[30000000];
int cnt;
int root[2000005];
int New(int x)
{
	t[++cnt].val=t[cnt].sum=x;
	t[cnt].rnd=rand();
	t[cnt].siz=1;
	return cnt;
}
void down(int p)
{
	if(t[p].tag)
	{
		if(t[p].l)
			t[++cnt]=t[t[p].l],t[p].l=cnt,t[cnt].tag^=1;
		if(t[p].r)
			t[++cnt]=t[t[p].r],t[p].r=cnt,t[cnt].tag^=1;
		swap(t[p].l,t[p].r);
		t[p].tag=0;
	}
}
void update(int p)
{
	t[p].siz=t[t[p].l].siz+t[t[p].r].siz+1;
	t[p].sum=t[t[p].l].sum+t[t[p].r].sum+t[p].val;	
}
int merge(int x,int y)
{
	if(!x||!y)
		return x|y;
	int cur=++cnt;
	down(x),down(y);
	if(t[x].rnd<t[y].rnd)
	{
		t[cur]=t[x];
		t[cur].r=merge(t[cur].r,y);
	}
	else
	{
		t[cur]=t[y];
		t[cur].l=merge(x,t[cur].l);
	}
	update(cur);
	return cur;
}
void split(int p,int v,int &x,int &y)
{
	if(!p)
		x=y=0;
	else
	{
		down(p);
		if(t[t[p].l].siz+1<=v)
		{
			x=++cnt;
			t[x]=t[p];
			split(t[x].r,v-t[t[p].l].siz-1,t[x].r,y);
			update(x);
		}
		else
		{
			y=++cnt;
			t[y]=t[p];
			split(t[y].l,v,x,t[y].l);
			update(y);
		}
	}
}
void insert(int x,int y,int p,int v)
{
	int a,b;
	split(root[y],p,a,b);
	root[x]=merge(a,merge(New(v),b));
}
void rev(int x,int y,int l,int r)
{
	int a,b,c;
	split(root[y],r,b,c);
	split(b,l-1,a,b);
	t[b].tag^=1;
	root[x]=merge(a,merge(b,c));
}
void del(int x,int y,int p)
{
	int a,b,c;
	split(root[y],p,b,c);
	split(b,p-1,a,b);
	root[x]=merge(a,c);
}
int query(int x,int y,int l,int r)
{
	int a,b,c;
	split(root[y],r,b,c);
	split(b,l-1,a,b);
	int res=t[b].sum;
	root[x]=merge(a,merge(b,c));
	return res;
}
int n;
int ans;
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		int v=read(),op=read(),l=(read()^ans),r;
		if(op!=2)
			r=(read()^ans);
		if(op==1)
			insert(i,v,l,r);
		else if(op==2)
			del(i,v,l);
		else if(op==3)
			rev(i,v,l,r);
		else
			write(ans=query(i,v,l,r)),puts("");
	}
}
2024/1/11 17:51
加载中...