pbds平衡树整理

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef pair<int,int> pii;
tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> bbt;
int n;
int main(){
	scanf("%d",&n);
	for (int i=1,opt,k; i<=n; ++i){
		scanf("%d%d",&opt,&k);
		if (opt==1) bbt.insert(make_pair(k,i));
		if (opt==2) bbt.erase(bbt.lower_bound(make_pair(k,0)));
		if (opt==3) printf("%d\n",bbt.order_of_key(make_pair(k,0))+1);
		if (opt==4){
			auto t=*bbt.find_by_order(k-1);
			printf("%d\n",t.first);
		}
		if (opt==5){
			ans=*--bbt.lower_bound(make_pair(k,0));
			printf("%d\n",ans);
		}
		if (opt==6){
			ans=*bbt.upper_bound(make_pair(k,n));
			printf("%d\n",ans);
		}
	}
}

洛谷P3369

posted @ 2020-10-20 22:22  Yuhuger  阅读(338)  评论(0编辑  收藏  举报