大家都很强, 可与之共勉 。
因为pbds
库里的平衡树相当于set
而不是multiset
,所以我们需要让它兹磁重复元素嘿嘿嘿。
实测rb_tree_tag
404ms
,splay_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 ;
}
}
}
}