QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#340568#4389. Copycrsfaa#ML 0ms0kbC++142.3kb2024-02-29 10:16:352024-02-29 10:16:35

Judging History

你现在查看的是最新测评结果

  • [2024-02-29 10:16:35]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-02-29 10:16:35]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
struct node
{
	int v,r,size,tag;
	int s[2];
}t[50000005];
#define ls t[w].s[0]
#define rs t[w].s[1]
int cnt;
int newnode(int v)
{
	t[++cnt].v=v,t[cnt].r=rand(),t[cnt].size=1;
	t[cnt].tag=t[cnt].s[0]=t[cnt].s[1]=0;
	return cnt;
}
int copy(int w)
{
	t[++cnt]=t[w];
	return cnt;
}
void pushup(int w)
{
	t[w].size=t[ls].size+t[rs].size+1;
}
void pushdown(int w)
{
	if(!t[w].tag) return;
	if(ls) ls=copy(ls);
	if(rs) rs=copy(rs);
	swap(ls,rs);
	if(ls) t[ls].tag^=1;
	if(rs) t[rs].tag^=1;
	t[w].tag=0;
}
void split(int w,int k,int &x,int &y)
{
	if(!w) 
	{
		x=y=0;
		return;	
	}
	pushdown(w);
	if(t[ls].size<k)
	{
		x=copy(w);
		split(t[x].s[1],k-t[ls].size-1,t[x].s[1],y);
		pushup(x);
	}
	else
	{
		y=copy(w);
		split(t[y].s[0],k,x,t[y].s[0]);
		pushup(y);
	}
}
int merge(int x,int y)
{
	if(!x||!y) return x+y;
	pushdown(x),pushdown(y);
	if(t[x].r<t[y].r)
	{
		t[x].s[1]=merge(t[x].s[1],y);
		pushup(x);
		return x;
	}
	else
	{
		t[y].s[0]=merge(x,t[y].s[0]);
		pushup(y);
		return y;
	}
}
int ask(int w,int k)
{
	if(t[ls].size+1==k) return t[w].v;
	if(t[ls].size+1<k) return ask(rs,k-t[ls].size-1);
	return ask(ls,k);
}
void print(int w)
{
	if(!w) return;
	print(ls),cout<<t[w].v<<',',print(rs);
}
int main()
{
	int T=read();
	while(T--)
	{
		int n=read(),m=read(),rt=0,sum=0,i;
		cnt=0;
		for(i=1;i<=n;i++)
			rt=merge(rt,newnode(read()));
//		print(rt),cout<<endl;
		while(m--)
		{
			int opt=read(),l=read();
			if(opt==1)
			{
				int r=read();
				int x,y,z,y1,y2,tp;
				split(rt,r,y,z);
				split(y,l-1,x,y1);
				split(y,l-1,tp,y2);	
//				print(x),cout<<endl;
//				print(y),cout<<endl;
//				print(y2),cout<<endl;
//				print(z),cout<<endl;
				rt=merge(merge(x,merge(y1,y2)),z);
				split(rt,n,rt,x);
//				print(rt),cout<<endl;
			}
			else sum^=ask(rt,l);
		}
		printf("%d\n",sum);
	}
}
/*
5
5 3
1 2 3 4 5
2 4
1 2 4
2 5
5 3
1 2 3 4 5
2 4
1 2 4
2 5
5 3
1 2 3 4 5
2 4
1 2 4
2 5
5 3
1 2 3 4 5
2 4
1 2 4
2 5
5 3
1 2 3 4 5
2 4
1 2 4
2 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

2
5 10
14138491 23289232 33892225 43531245 54436322
1 1 4
2 2
2 3
2 4
2 5
1 2 4
2 2
2 3
2 4
2 5
99990 99990
493133979 94198606 751145654 147404311 601524088 744747426 561746143 212260573 241231749 810352224 81276441 382492450 18779020 317505899 880615584 654793240 417574821 822313301 140569958 69317...

output:


result: