只A了一个点,样例也过不了,还T……
查看原帖
只A了一个点,样例也过不了,还T……
224212
小船儿楼主2020/9/12 17:19
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN=1100010;
struct Node{ int ch[2],ff,sz,s,v; }t[MAXN];
//0左,1右 
int root,tot;

void pushup(int x) { t[x].sz=t[t[x].ch[0]].sz+t[t[x].ch[1]].sz+t[x].s; }

void rotate(int x)
{
	int y=t[x].ff,z=t[y].ff;
	int k=( t[y].ch[1]==x );
	t[z].ch[t[z].ch[1]==y]=x;t[x].ff=z;
	t[y].ch[k]=t[x].ch[k^1];t[t[x].ch[k^1]].ff=y;
	t[x].ch[k^1]=y;t[y].ff=x;
	pushup(y);pushup(x);
}

void Splay(int x,int goal)
{
	while(t[x].ff!=goal)
	{
		int y=t[x].ff,z=t[y].ff;
		if(z!=goal)
		  (t[y].ch[0]==x)^(t[z].ch[0]==y) ? rotate(x) : rotate(y);
		rotate(x);
	}
	if(goal==0) root=x;
}

void insert(int v)
{
	int x=root,ff=0;
	while(x&&t[x].v!=v) ff=x,x=t[x].ch[v>t[x].v];
	if(x) t[x].s++;
	else 
	{
		x=++tot;
		if(ff) t[ff].ch[x>t[ff].v]=x;
		//t[x].ch[0]=t[x].ch[1]=0;
		t[x].sz=t[x].s=1; t[x].v=v; t[x].ff=ff;
	}
	Splay(x,0);
}

void Find(int v)
{
	int x=root;
	if(!x) return ;
	while( t[x].v!=v&&t[x].ch[v>t[x].v] ) x=t[x].ch[v>t[x].v];
	Splay(x,0);
}

int Next(int v,int f)//f=0时找前驱,f=1时找后继 
{
	Find(v); int x=root;
	if(t[x].v>v&&f)  return x;
	if(t[x].v<v&&!f)  return x;
	x=t[x].ch[f];
	while(t[x].ch[f^1]) x=t[x].ch[f^1];
	return x;
}

void Delete(int v)
{
	int x=Next(v,0),y=Next(v,1);
	Splay(x,0);Splay(y,x);
	int z=t[y].ch[0];
	if(t[z].s>1) t[z].s--,Splay(z,0);
	else t[y].ch[0]=0,pushup(y),pushup(x);
}

int Kth(int k)
{
	int x=root;
	if(t[x].sz-1<=k) k=t[x].sz-1;
	while(1)
	{
		if(k>t[t[x].ch[0]].sz+t[x].s) k-=t[t[x].ch[0]].sz+t[x].s,x=t[x].ch[1];
		else if(k<=t[t[x].ch[0]].sz) x=t[x].ch[0];
		else return t[x].v;
	}
}

int main()
{
	insert(-2147483647);insert(+2147483647);
	int n,m;
	scanf("%d%d",&n,&m);
	while(n--) {int x;scanf("%d",&x);insert(x);}
	int last=0;
	int ans=0;
	while(m--)
	{
		int opt,x;
		scanf("%d%d",&opt,&x);
		switch(opt)
		{
			case 1:insert(x^last);break;
			case 2:Delete(x^last);break;
			case 3:Find(x^last),last=t[t[root].ch[0]].sz,ans^=last;break;
			case 4:last=Kth((x^last)+1),ans^=last;break;
			case 5:last=Next(x^last,0),ans^=last;break;
			case 6:last=Next(x^last,1),ans^=last;break;
		}
	}
	printf("%d",ans);
	return 0;
}

非加强版的可以过

2020/9/12 17:19
加载中...