zoukankan      html  css  js  c++  java
  • 【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
    ",T.order_of_key(x<<20)+1);
            else if (opt==4)
                printf("%lld
    ",*T.find_by_order(x-1)>>20);
            else if (opt==5)
            {
                map<int,int>::iterator key=MP.lower_bound(x);
                key--;
                printf("%d
    ",key->first);
            }
            else
            {
                map<int,int>::iterator key=MP.upper_bound(x);
                printf("%d
    ",key->first);
            }
        }
        return 0;
    }
    
    

      

  • 相关阅读:
    NO.2
    【转载】初始化顺序
    Java中的容器
    primer看完了
    NO.1
    转 Python爬虫入门二之爬虫基础了解
    转 Python爬虫入门一之综述
    hdu 5691 Sitting in Line
    51nod 1043 幸运号码
    51nod 1624 取余最长路
  • 原文地址:https://www.cnblogs.com/yangjiyuan/p/5761016.html
Copyright © 2011-2022 走看看