QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#484503#21403. 文艺平衡树275307894aWA 0ms8124kbC++142.1kb2024-07-19 19:41:452024-07-19 19:41:45

Judging History

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

  • [2024-07-19 19:41:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:8124kb
  • [2024-07-19 19:41:45]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned ll;using pii=pair<int,int>;
const int N=2e5+5,M=N*100+5,K=1e7+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=5e18+7;mt19937 rnd(time(0));
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,m,rt;
namespace FHQ{
	int rd[N],l[N],r[N],g[N],val[N],siz[N],cnt;
	int newnode(int x){
		siz[++cnt]=1;val[cnt]=x;rd[cnt]=rnd();
		return cnt;
	}
	void up(int v){siz[v]=siz[l[v]]+siz[r[v]]+1;}
	void Pg(int v){if(v) g[v]^=1,swap(l[v],r[v]);}
	void P(int v){if(g[v]) Pg(l[v]),Pg(r[v]),g[v]=0;}
	void split(int x,int v,int &a,int &b){
		if(!v){a=b=0;return;}P(v);
		if(x>=siz[l[v]]+1) a=v,split(x-siz[l[v]]-1,r[v],r[a],b);
		else b=v,split(x,l[v],a,l[b]);
		up(v);
	}
	int merge(int x,int y){
		if(!x||!y) return x|y;P(x);P(y);
		if(rd[x]<rd[y]) return r[x]=merge(r[x],y),up(x),x;
		else return l[y]=merge(x,l[y]),up(y),y;
	}
	void print(int v){
		if(!v) return;
		print(l[v]);
		printf("%d ",val[v]);
		print(r[v]);
	}
}
void Solve(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) rt=FHQ::merge(rt,FHQ::newnode(i));
	while(m--){
		int x,y;scanf("%d%d",&x,&y);
		int r1,r2,r3;
		FHQ::split(x-1,rt,r1,r2);
		FHQ::split(y-x+1,r2,r2,r3);
		FHQ::Pg(r2);
		rt=FHQ::merge(FHQ::merge(r1,r2),r3);
	}
	FHQ::print(rt);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

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

input:

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

output:

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