求助pbds tree
查看原帖
求助pbds tree
221955
panyf楼主2020/10/3 23:29
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
tree<pair<int,int>,null_type,less<pair<int,int> >,splay_tree_tag,tree_order_statistics_node_update>t;
gp_hash_table<int,int>mp;
int main(){
	int n,o,x;
	for(scanf("%d",&n);n--;){
		scanf("%d%d",&o,&x);
		if(o==1)t.insert({x,++mp[x]});
		else if(o==2)t.erase({x,mp[x]--});
		else if(o==3)printf("%d\n",t.order_of_key({x,0})+1);
		else if(o==4)printf("%d\n",t.find_by_order(x-1)->first);
		else if(o==5)printf("%d\n",t.find_by_order(t.order_of_key({x,0})-1)->first);
		else printf("%d\n",t.find_by_order(t.order_of_key({x,1e9}))->first);
	}
	return 0;
}

rt,上面的代码第12个测试点TLE,将splay_tree_tag改成rb_tree_tag 39ms通过(都开了O2)

求解释原因怀疑splay_tree_tag是单旋

2020/10/3 23:29
加载中...