zoukankan      html  css  js  c++  java
  • vector妙用轻松水过平衡树???

    极短代码预警

    今天听身边的神仙说,可以用vector来写平衡树,代码极短。
    然后去网上搜了一下,看到了attack dalao的这篇文章。
    蒟蒻表示ssfd
    赶紧膜拜了一波,并发表了一篇博客表示纪念。

    #include<cstdio>
    #include<vector>
    #include<algorithm>
    using namespace std;
    vector<int>v;
    int n,opt,x;
    int main()
    {
        v.reserve(100001);
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d%d",&opt,&x);
            if(opt==1)    v.insert(lower_bound(v.begin(),v.end(),x),x);
            if(opt==2)    v.erase (lower_bound(v.begin(),v.end(),x));
            if(opt==3)    printf("%d
    ",lower_bound(v.begin(),v.end(),x)-v.begin()+1);
            if(opt==4)    printf("%d
    ",v[x-1]);
            if(opt==5)    printf("%d
    ",v[lower_bound(v.begin(),v.end(),x)-v.begin()-1]);
            if(opt==6)    printf("%d
    ",v[upper_bound(v.begin(),v.end(),x)-v.begin()]);
        }
        return 0;
    }
    

    实测轻松碾压我的splay和fhq。。。。。

  • 相关阅读:
    hdu5514 非2的次幂容斥原理
    「NOIP2015」斗地主
    「NOIP2009」靶形数独
    「CF521D」Shop
    「HNOI2015」菜肴制作
    「NOIP2011」观光公交
    「NOI2015」荷马史诗
    「JSOI2007」建筑抢修
    「CF161B」Discounts
    叠罗汉
  • 原文地址:https://www.cnblogs.com/fengxunling/p/10328869.html
Copyright © 2011-2022 走看看