【bzoj3224】Tyvj 1728 普通平衡树

交了一发pb_ds

 

#include<ext/pb_ds/assoc_container.hpp>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
using namespace __gnu_pbds;
using namespace std;
 
typedef long long LL;
 
tree<LL,null_mapped_type,less<LL>,rb_tree_tag,tree_order_statistics_node_update>T;
 
map<int,int>MP;
 
int Q,opt;
 
LL x;
 
int main()
{
    scanf("%d",&Q);
    while (Q--)
    {
        scanf("%d%lld",&opt,&x);
        if (opt==1)
            T.insert((x<<20)+(MP[x]++));
        else if (opt==2)
        {
            T.erase(T.find((x<<20)+(--MP[x])));
            if (!MP[x])
                MP.erase(MP.find(x));
        }
        else if (opt==3)
            printf("%d\n",T.order_of_key(x<<20)+1);
        else if (opt==4)
            printf("%lld\n",*T.find_by_order(x-1)>>20);
        else if (opt==5)
        {
            map<int,int>::iterator key=MP.lower_bound(x);
            key--;
            printf("%d\n",key->first);
        }
        else
        {
            map<int,int>::iterator key=MP.upper_bound(x);
            printf("%d\n",key->first);
        }
    }
    return 0;
}

  

posted @ 2016-08-11 15:09  Yangjiyuan  阅读(128)  评论(0编辑  收藏  举报