为什么会全部MLE?
查看原帖
为什么会全部MLE?
523525
徐天乾楼主2021/8/3 14:09

如题,在线等,急!

#include<bits/stdc++.h>
#define M 130100
using namespace std;
int son[M][2],size[M],rep[M],w[M],f[M],T,O,root,x;char c[4];
void update(int x)  {size[x]=x?rep[x]+size[son[x][0]]+size[son[x][1]]:size[x];}
int get(int x)  {return son[f[x]][1]==x;}
int con(int x,int y,int z)  {f[x]=x?y:f[x]; son[y][z]=y?x:son[y][z];}
void clea(int x)  {son[x][0]=son[x][1]=f[x]=rep[x]=w[x]=size[x]=0;} 
void spin(int x){
	int t=f[x],w=f[t],T=get(x),W=get(t);
	con(son[x][!T],t,T);con(t,x,!T);con(x,w,W); 
	update(t);update(x);
}
void splay(int x){
	for (int t;t=f[x];spin(x))  
		if (f[t]) spin(get(x)==get(t)?t:x);
	root=x;
}
int ask(int x){                            
	int t=root;
	for(;1;){
		if (x<=size[son[t][0]])  {t=son[t][0];continue;}
		x-=size[son[t][0]];
		if (x<=rep[t])  {splay(t);return w[t];}
		x-=rep[t];t=son[t][1];
	}
} 
void ins(int x){                         
	if (!root){
		root=++O;w[O]=x;
		size[O]=rep[O]=1;
		return ;
	}
	int t=root,t_=0;
	for (;1;){ 
		if (w[t]==x)   {rep[t]++;update(t);update(t_);splay(t);return ;}
		t_=t;t=son[t][x>w[t]];
		if (!t){
			w[++O]=x;size[O]=rep[O]=1; 
			f[O]=t_;son[t_][x>w[t_]]=O; 
			update(t_);splay(O);return ;
		}
	}
}
int min(int x,int y){return x<y?x:y;}
int main(){
	for (scanf("%d",&T);T;T--)
		scanf("%d",&x),ins(x);
	scanf("%d",&T); 
	while (T--){
		scanf("%s",c);
		if (c[0]=='a') scanf("%d",&x),ins(x);
		if (c[0]=='m') printf("%d\n",(O&1)?ask(O/2+1):min(ask(O/2),ask(O/2+1))); 
	} 
}
2021/8/3 14:09
加载中...