QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#482777#21403. 文艺平衡树ucup-team1004WA 0ms3940kbC++171.5kb2024-07-17 21:29:052024-07-17 21:29:06

Judging History

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

  • [2024-07-17 21:29:06]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3940kb
  • [2024-07-17 21:29:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=1e5+10;
struct node{
	int ls,rs,rnd,rev,val,siz;
}t[N];
void pushup(int rt){
	t[rt].siz=t[t[rt].ls].siz+t[t[rt].rs].siz+1;
}
void pushrev(int rt){
	swap(t[rt].ls,t[rt].rs),t[rt].rev^=1;
}
void pushdown(int rt){
	if(t[rt].rev){
		pushrev(t[rt].ls);
		pushrev(t[rt].rs);
		t[rt].rev=0;
	}
}
void split(int rt,int k,int &x,int &y){
	if(!rt)return x=y=0,void();
	pushdown(rt);
	if(k<=t[t[rt].ls].siz)y=rt,split(t[rt].ls,k,x,t[rt].ls);
	else x=rt,split(t[rt].rs,k-t[t[rt].ls].siz-1,t[rt].rs,y);
	pushup(rt);
}
int merge(int x,int y){
	if(!x||!y)return x|y;
	if(t[x].rnd<t[y].rnd){
		pushdown(x);
		t[x].rs=merge(t[x].rs,y);
		return pushup(x),x;
	}else{
		pushdown(y);
		t[y].ls=merge(x,t[y].ls);
		return pushup(y),y;
	}
}
int n,m,root;
mt19937 rnd(time(0));
void print(int rt){
	if(!rt)return;
	print(t[rt].ls);
	printf("%d ",t[rt].val);
	print(t[rt].rs);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		t[i]={0,0,(int)rnd(),0,i,1};
		root=merge(root,i);
	}
	for(int l,r;m--;){
		scanf("%d%d",&l,&r);
		int r1,r2,r3;
		split(root,r,r2,r3);
		split(r2,l-1,r1,r2);
		pushrev(r2);
		root=merge(merge(r1,r2),r3);
	}
	print(root);
	puts("");
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3940kb

input:

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

output:

1 2 4 17 16 15 5 6 18 19 20 21 22 23 3 24 25 26 14 13 11 12 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 2 4 17 16 15 5 6 18 19 20 21... 13 11 12 10 9 8 7 27 28 29 30 '