60求助——来自一只pbds的小菜鸡
查看原帖
60求助——来自一只pbds的小菜鸡
365532
Mr_ll楼主2021/10/21 14:36

超丑码风预警

(蒟蒻因为临近复赛却不会平衡树,就去拿了点平板电视垫了垫,勿········)

#include<iostream>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<ext/rope>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rt;
map<int,int> mapp;
int n,op,x;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&op,&x);
		if(op==1){if(!mapp[x])rt.insert(x); mapp[x]++;}
		if(op==2){if(!mapp[x])continue; if(mapp[x]==1)rt.erase(x); mapp[x]--;}
		if(op==3)printf("%d\n",rt.order_of_key(x)+1);
		if(op==4)printf("%d\n",*rt.find_by_order(x-1));
		if(op==5)printf("%d\n",*--rt.lower_bound(x));
		if(op==6)printf("%d\n",*rt.upper_bound(x));
	}
	return 0;
}
2021/10/21 14:36
加载中...