码迷,mamicode.com
首页 > 其他好文 > 详细

【luogu P3369 【模板】普通平衡树(Treap/SBT)】 题解 pb_ds

时间:2018-06-22 22:49:39      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:lower   nta   ++   str   scanf   key   containe   using   find   

我永远都爱STL ! 我爱PB_DS !

#include <iostream>
#include <cstdio>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef long long ll;
tree<ll,null_type,std::less<ll>,splay_tree_tag,tree_order_statistics_node_update> st;
int main()
{
    int m;
    ll ans, x, y;
    scanf("%d",&m);
    for(int i = 1; i <= m; i++)
    {
        scanf("%lld%lld",&x,&y);
        if(x == 1) st.insert((y<<20)+i);
        else if(x == 2) st.erase(st.lower_bound(y<<20));
        else if(x == 3) printf("%d\n",st.order_of_key(y<<20)+1);
        else {
            if(x == 4) ans = *st.find_by_order(y-1);
            if(x == 5) ans = *--st.lower_bound(y<<20);
            if(x == 6) ans = *st.lower_bound((y+1)<<20);
            printf("%lld\n",ans>>20);
        }
    }
    return 0;
}

其实还可以用set,vector做...
我永远都喜欢stl

【luogu P3369 【模板】普通平衡树(Treap/SBT)】 题解 pb_ds

标签:lower   nta   ++   str   scanf   key   containe   using   find   

原文地址:https://www.cnblogs.com/MisakaAzusa/p/9215543.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!