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;
    }
    
    

      

  • 相关阅读:
    python登录qq
    js加解密的算法
    python request模板
    qq查询接口
    python代理池的实现
    mvvm实现
    消息队列
    【Linux常见命令】seq命令
    【Linux常见命令】find命令
    【Linux常见命令】rm命令
  • 原文地址:https://www.cnblogs.com/yangjiyuan/p/5761016.html
Copyright © 2011-2022 走看看