冒泡——pb_ds库 水 BZOJ3224普通平衡树

大家都很强, 可与之共勉 。

因为pbds库里的平衡树相当于set而不是multiset,所以我们需要让它兹磁重复元素嘿嘿嘿。
实测rb_tree_tag 404mssplay_tree_tag 544ms
学到老活到老233333

# include <bits/stdc++.h>
# include <ext/pb_ds/tree_policy.hpp>
# include <ext/pb_ds/hash_policy.hpp>
# include <ext/pb_ds/assoc_container.hpp>

using namespace std ;
using namespace __gnu_pbds ;

inline int read ( )  {
    register int x, c ;
    bool opt ( 1 ) ;
    while ( isspace ( c = getchar ( ) ) && ( c != 45 ) ) ;
    if ( c == 45 )  opt = 0, c = getchar ( ) ;
    for ( x = -48 + c ; isdigit ( c = getchar ( ) ) ; ( x *= 10 ) += c - 48 ) ;
    return opt ? x : -x ;
}

gp_hash_table < int, int > H ;
tree < pair < int, int >, null_mapped_type, less < pair < int, int > >, rb_tree_tag, tree_order_statistics_node_update > T ;
//tree < pair < int, int >, null_type, less < pair < int, int > >, rb_tree_tag, tree_order_statistics_node_update > T ;

int main ( )  {
    int n ( read ( ) ) ;
    while ( n -- )  {
        static int opt, x ;
        opt = read ( ), x = read ( ) ;
        switch ( opt )  {
            case 1 :  {
                T.insert ( make_pair ( x, ++ H [x] ) ) ;
                break ;
            }
            case 2 :  {
                T.erase ( make_pair ( x, H [x] --) ) ;
                break ;
            }
            case 3 :  {
                printf ( "%d\n", ( int ) T.order_of_key ( make_pair ( x, 0 ) ) + 1 ) ;
                break ;
            }
            case 4 :  {
                printf ( "%d\n", T.find_by_order ( x - 1 ) -> first ) ;
                break ;
            }
            case 5 :  {
                printf ( "%d\n", T.find_by_order ( T.order_of_key ( make_pair ( x, 0 ) ) - 1 ) -> first ) ;
                break ;
            }
            case 6 :  {
                printf ( "%d\n", T.upper_bound ( make_pair ( x, INT_MAX ) ) -> first ) ;
                break ;
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值