_pbds 平衡树求调
查看原帖
_pbds 平衡树求调
174806
xbb2楼主2022/8/9 18:34
//#include<bits/extc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
int n,cnt=0;map<int,int> mp;
__gnu_pbds::tree<
	pair<int,int>,
	null_type,
	std::less<pair<int,int> >,
	__gnu_pbds::rb_tree_tag,
	__gnu_pbds::tree_order_statistics_node_update>t;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int opt,x;scanf("%d%d",&opt,&x);
		if(opt==1)t.insert(make_pair(x,++cnt)),mp[x]=cnt;
		else if(opt==2)t.erase(make_pair(x,(*t.lower_bound(make_pair(x,1))).second));
		else if(opt==3)printf("%d\n",t.order_of_key(make_pair(x,(*t.lower_bound(make_pair(x,1))).second))+1);
		else if(opt==4)printf("%d\n",*t.find_by_order(x-1));
		else if(opt==5)printf("%d\n",*t.find_by_order(t.order_of_key(make_pair(x,(*t.lower_bound(make_pair(x,1))).second))-1));
		else if(opt==6)printf("%d\n",*t.find_by_order(t.order_of_key(make_pair(x,(*t.upper_bound(make_pair(x,cnt))).second))));
		else while(1)printf("309133584\n");
	}
	return 0;
}

52分WA,RT

2022/8/9 18:34
加载中...