QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#341294#21403. 文艺平衡树ffffyc#WA 1ms5892kbC++142.5kb2024-02-29 17:29:412024-02-29 17:29:42

Judging History

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

  • [2024-02-29 17:29:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5892kb
  • [2024-02-29 17:29:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace IO{//by cyffff
	int len=0;
	char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
	#if ONLINE_JUDGE
	#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
 	#else
	#define gh() getchar()
	#endif
	#define reg register
	inline int read(){
		reg char ch=gh();
		reg int x=0;
		reg char t=0;
		while(ch<'0'||ch>'9')   t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
		return t?-x:x;
	}
	inline void putc(char ch){
		out[len++]=ch;
	}
	template<class T>
	inline void write(T x){
		if(x<0)putc('-'),x=-x;
		if(x>9)write(x/10);
		out[len++]=x%10+48;
	}
	inline void flush(){
		fwrite(out,1,len,stdout);
		len=0;
	}
	inline char getc(){
		char ch=gh();
		while(ch<'A'||ch>'Z') ch=gh();
		return ch;
	}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
const int N=1e5+10;
mt19937 R(time(0)*rand());
int n,m,rt;
struct FHQ_Treap{
	#define ls (a[rt].lss)
	#define rs (a[rt].rss)
	struct node{
		int lss,rss,siz,v,pr;
		bool tag;
	}a[N];
	int siz;
	inline int newnode(int v){
		int rt=++siz;
		a[rt].siz=1,a[rt].v=v;
		a[rt].pr=R();
		return rt;
	}
	inline void pushup(int rt){
		a[rt].siz=a[ls].siz+a[rs].siz+1;
	}
	inline void pushtag(int rt){
		a[rt].tag^=1,swap(ls,rs);
	}
	inline void pushdown(int rt){
		if(!a[rt].tag) return ;
		if(ls) pushtag(ls);
		if(rs) pushtag(rs);
		a[rt].tag=0;
	}
	inline int merge(int x,int y){
		if(!x||!y) return x+y;
		if(a[x].pr>a[y].pr){
			pushdown(x);
			a[x].rss=merge(a[x].rss,y);
			pushup(x);
			return x;
		}else{
			pushdown(y);
			a[y].lss=merge(x,a[y].lss);
			pushup(y);
			return y;
		}
	}
	inline void split(int rt,int &x,int &y,int k){
		if(!rt){ x=y=0;return ; }
		pushdown(rt);
		if(a[ls].siz>=k) y=rt,split(ls,x,ls,k);
		else x=rt,split(rs,rs,y,k-a[ls].siz-1);
		pushup(rt);
	}
	int rt,A,B,C;
	inline void build(int &rt,int l,int r){
		if(l>r){ rt=0;return ; }
		int mid=l+r>>1;
		rt=newnode(mid);
		build(ls,l,mid-1),build(rs,mid+1,r);
	}
	inline void reverse(int &rt,int l,int r){
		split(rt,A,B,l-1),split(B,B,C,r-l+1);
		pushtag(B);
		rt=merge(A,merge(B,C));
	}
	inline void dfs(int rt){
		if(!rt) return ;
		pushdown(rt);
		dfs(ls),write(a[rt].v),putc(' '),dfs(rs);
	}
}T;
int main(){
	n=read(),m=read();
	T.build(rt,1,n);
	while(m--){
		int l=read(),r=read();
		T.reverse(rt,l,r);
	}
	T.dfs(rt);
	flush();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5892kb

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 17 18 19 20 21 22 23 28 27 26 25 24 29 30 16 

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 3 4 5 6 7 8 9 10 11 12 13 ... 22 23 28 27 26 25 24 29 30 16 '