#include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;
使用方法
/*
定义一颗红黑树
int 关键字类型
null_type无映射(低版本g++为null_mapped_type)
less<int>从小到大排序
rb_tree_tag 红黑树(splay_tree_tag)
tree_order_statistics_node_update结点更新
插入t.insert();
删除t.erase();
Rank:t.order_of_key();
第K值:t.find_by_order();
前驱:t.lower_bound();
后继t.upper_bound();
a.join(b)b并入a 前提是两棵树的key的取值范围不相交
a.split(v,b)key小于等于v的元素属于a,其余的属于b
T.lower_bound(x) >=x的min的迭代器
T.upper_bound((x) >x的min的迭代器
T.find_by_order(k) 有k个数比它小的数
*/
例如:
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define LL long long
#define INF 1E4 * 1E9
#define pi acos(-1)
#define endl '\n'
#define me(x) memset(x,0,sizeof(x));
const int maxn=1e3+5;
const int maxx=1e7+5;
//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> set_t;
set_t S;
queue<int >s;
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int x,cnt;
scanf("%d",&x);
if(x==1)
{
scanf("%d",&cnt);
S.insert(cnt);
s.push(cnt);
}
if(x==2)
{
int T=s.front();
s.pop();
S.erase(T);
}
if(x==3)
{
// cout<<cnt<<"******cnt"<<endl;
int len=s.size();
int num=len/2;
// it=S.begin();
//cout<<*it<<"********"<<endl;
cout<<*S.find_by_order(num)<<endl;
}
}
}