Luogu P3396普通平衡树

来源:互联网 发布:python 绝顶黑客 编辑:程序博客网 时间:2024/06/05 05:58

这道题真的很简单

就是模板题

主代码部分:

tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>t;ll T,opt,num;int main(){#ifndef ONLINE_JUDGE    freopen("","r",stdin);    freopen("","w",stdout);#endif    T=read();    while(T--)    {        opt=read();        num=read();        if(opt==1)            t.insert((num<<20)+T);        if(opt==2)            t.erase(t.lower_bound(num<<20));        if(opt==3)            printf("%lld\n",t.order_of_key(num<<20)+1);        if(opt==4)            printf("%lld\n",*t.find_by_order(num-1)>>20);        if(opt==5)            printf("%lld\n",*(--t.lower_bound(num<<20))>>20);        if(opt==6)            printf("%lld\n",*t.upper_bound((num+1)<<20)>>20);    }    rt 0;}

头文件要加上

#include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/tree_policy.hpp>using namespace __gnu_pbds;

有个小处理是为了处理重复

原创粉丝点击