QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93307#21403. 文艺平衡树Appleblue17#WA 2ms3384kbC++141.7kb2023-03-31 16:49:392023-03-31 16:49:41

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-31 16:49:41]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3384kb
  • [2023-03-31 16:49:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;

#define ls(o) tr[o].s[0]
#define rs(o) tr[o].s[1]

struct tree{
	int fa,s[2],siz,tag;
}tr[N];
void pushup(int o){
	tr[o].siz=tr[ls(o)].siz+tr[rs(o)].siz+1;
}
void addtag(int o){
	tr[o].tag^=1;
	swap(ls(o),rs(o));
}
void pushdown(int o){
	if(tr[o].tag){
		addtag(ls(o));
		addtag(rs(o));
		tr[o].tag=0;
	}
}
void rotate(int x){
	int y=tr[x].fa,z=tr[y].fa;
	pushdown(y);
	pushdown(x);
	int ky=(rs(y)==x),kz=(rs(z)==y);
	int B=tr[x].s[ky^1]; tr[y].s[ky]=B; tr[B].fa=y;
	tr[x].s[ky^1]=y; tr[y].fa=x;
	tr[z].s[kz]=x; tr[x].fa=z;
	pushup(y);
	pushup(x);
}
void splay(int x,int g=0){
	while(tr[x].fa && tr[x].fa!=g){
		int y=tr[x].fa,z=tr[y].fa;
		if(z && z!=g){
			if((rs(y)==x)==(rs(z)==y)) rotate(y);
			else rotate(x);
		}
		rotate(x);
	}
}

int kth(int k){
	splay(1);
	int x=1;
	while(x){
		pushdown(x);
		int siz=tr[ls(x)].siz;
		if(k==siz+1){
			splay(x);
			return x;
		}
		else if(k<siz+1) x=ls(x);
		else k-=siz+1,x=rs(x);
	}
	return -1;
}

int n,m;
void dfs(int u){
	if(!u) return ;
	pushdown(u);
	dfs(ls(u));
	if(u>=2 && u<=n+1) cout<<u-1<<" ";
	dfs(rs(u));
}

void pr(int o){
	if(!o) return ;
	cout<<" "<<o<<": "<<ls(o)<<" "<<rs(o)<<"  "<<tr[o].siz<<'\n';
	pushdown(o);
	pr(ls(o));
	pr(rs(o));
}

int main(){
	// ios::sync_with_stdio(false);
	// cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n+2;i++) tr[i].siz=n+3-i;
	for(int i=1;i<=n+1;i++){
		tr[i].s[1]=i+1;
		tr[i+1].fa=i;
	}
	// splay(1);
	// pr(1);
	while(m--){
		int l,r; cin>>l>>r; l++,r++;
		int x=kth(l-1),y=kth(r+1);
		splay(x);
		splay(y,x);
		addtag(ls(y));
		
		// splay(1);
		// pr(1);
	}
	
	// splay(1);
	dfs(1);
}

详细

Test #1:

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

input:

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

output:

1 

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 '