QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#342443#21403. 文艺平衡树do_while_true#WA 1ms3572kbC++143.2kb2024-03-01 11:24:502024-03-01 11:24:51

Judging History

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

  • [2024-03-01 11:24:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3572kb
  • [2024-03-01 11:24:50]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<array>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
const int L=1<<21;
char buf[L],*p=buf+L;
int tmpfrd;
char gc(){
	if(p==buf+L)tmpfrd=fread(p=buf,1,L,stdin);
	return *p++;
}
template<typename T>
T &read(T &r){
	r=0;bool w=0;char ch=gc();
	while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=gc();
	while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=gc();
	return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
	int s=1;
	while(y){
		if(y&1)s=1ll*s*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return s;
}
mt19937 rnd(233);
const int N=100010;
int n,m;
#define ls(x) ch[x][0]
#define rs(x) ch[x][1]
int rt,tot;
int siz[N],val[N],tag[N];
int ch[N][2];
unsigned c[N];
inline int newnode(int v){int x=++tot;siz[x]=1;val[x]=v;c[x]=rnd();return x;}
inline void pushup(int x){siz[x]=siz[ls(x)]+siz[rs(x)]+1;}
inline void pushdown(int x){
	if(tag[x]){
		swap(ls(x),rs(x));
		if(ls(x))tag[ls(x)]^=1;
		if(rs(x))tag[rs(x)]^=1;
		tag[x]=0;
	}
}
int merge(int x,int y){
	if(!x||!y)return x|y;
	int k=c[x]<c[y],u=k?x:y;
	pushdown(x);pushdown(y);
	if(k)ch[u][k]=merge(rs(x),y);
	else ch[u][k]=merge(x,ls(y));
	pushup(u);
	return u;
}
void split(int u,int k,int &x,int &y){
	if(!u){x=y=0;return ;}
	// DE("%d son: %d %d ; val: %d ; siz: %d",u,ls(u),rs(u),val[u],siz[u]);
	// dbg(k);
	// if(u==0)assert(0);
	pushdown(u);
	if(siz[ls(x)]+1<=k){
		x=u;
		split(rs(u),k-siz[ls(x)]-1,rs(x),y);
		pushup(x);
	}
	else{
		y=u;
		split(ls(u),k,x,ls(y));
		pushup(y);
	}
}
void dfs(int x){
	pushdown(x);
	if(ls(x))dfs(ls(x));
	cout<<val[x]<<' ';
	if(rs(x))dfs(rs(x));
}
signed main(){
	// #ifdef do_while_true
		// assert(freopen("data.in","r",stdin));
		// assert(freopen("data.out","w",stdout));
	// #endif
	read(n,m);
	for(int i=1;i<=n;i++){
		rt=merge(rt,newnode(i));
	}
	for(int i=1;i<=m;i++){
		int l,r;read(l,r);
		int a,b,c;
		split(rt,l-1,a,b);
		split(b,r-l+1,b,c);
		tag[b]^=1;
		rt=merge(merge(a,b),c);
	}
	dfs(rt);
    #ifdef do_while_true
//		cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
	#endif
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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 

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 ... 21 22 23 24 25 26 27 28 29 30 '