QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#92617#21403. 文艺平衡树cc000#WA 2ms3720kbC++141.5kb2023-03-30 19:50:372023-03-30 19:50:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 19:50:45]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3720kb
  • [2023-03-30 19:50:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn=200002;
mt19937 myrand(time(0));
int Rand(int x,int y)
{
	unsigned a=myrand();
	return a%(y-x+1)+x;
}
int lson[maxn],rson[maxn],c[maxn],tag[maxn],siz[maxn];
void pushup(int p){siz[p]=siz[lson[p]]+1+siz[rson[p]];}
void pushdown(int p)
{
	if(lson[p])
	{
		swap(lson[lson[p]],rson[lson[p]]);
		tag[lson[p]]^=tag[p];
	}
	if(rson[p])
	{
		swap(lson[rson[p]],rson[rson[p]]);
		tag[rson[p]]^=tag[p];
	}
	tag[p]=0;
}
int merge(int x,int y) 
{
	if(!x||!y) return x+y;
	if(Rand(0,1)) 
	{
		if(tag[x]) pushdown(x);
		rson[x]=merge(rson[x],y);
		pushup(x);
		return x;
	}
	else
	{
		if(tag[y]) pushdown(y);
		lson[y]=merge(x,lson[y]);
		pushup(y);
		return y;
	}
}
void split(int p,int k,int &x,int &y)
{
	if(!p) return x=0,y=0,void();
	if(tag[p]) pushdown(p);
	if(k<=siz[lson[p]]) y=p,split(lson[p],k,x,lson[p]),pushup(y);
	else x=p,split(rson[p],k-siz[lson[p]]-1,rson[p],y),pushup(x);
}
void dfs(int p)
{
	if(!p) return;
	if(tag[p]) pushdown(p);
	dfs(lson[p]); 
	printf("%d\n",c[p]);
	dfs(rson[p]);
}
int main()
{
	//freopen("A.in","r",stdin);
	int n,m;int rt=1; c[1]=1; siz[1]=1;
	scanf("%d%d",&n,&m);
	for(int i=2;i<=n;i++) 
	{
		c[i]=i; siz[i]=1; 
		rt=merge(rt,i);
	}
	dfs(rt);
	while(m--)
	{
		int x,y,z;
		int l,r; scanf("%d%d",&l,&r);
		split(rt,l-1,x,y); 
		split(y,r-l+1,y,z);
		tag[y]^=1; swap(lson[y],rson[y]);
		y=merge(y,z);
		rt=merge(x,y);
	}
	dfs(rt);
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3720kb

input:

30 5
7 26
7 18
5 9
4 15
3 15

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
4
17
16
15
6
5
18
19
20
21
22
23
3
24
25
26
14
13
12
11
10
9
8
7
27
28
29
30

result:

wrong answer 1st lines differ - expected: '1 2 4 17 16 15 6 5 18 19 20 21...4 13 12 11 10 9 8 7 27 28 29 30', found: '1'