• bzoj 3224 普通平衡树 vactor的妙用


    3224: Tyvj 1728 普通平衡树

    Time Limit: 1 Sec  Memory Limit: 256 MB

    题目连接

    http://www.lydsy.com/JudgeOnline/problem.php?id=3224

    Description

    您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:
    1. 插入x数
    2. 删除x数(若有多个相同的数,因只删除一个)
    3. 查询x数的排名(若有多个相同的数,因输出最小的排名)
    4. 查询排名为x的数
    5. 求x的前驱(前驱定义为小于x,且最大的数)
    6. 求x的后继(后继定义为大于x,且最小的数)

    Input

    第一行为n,表示操作的个数,下面n行每行有两个数opt和x,opt表示操作的序号(1<=opt<=6)

    Output

    对于操作3,4,5,6每行输出一个数,表示对应答案

    Sample Input

    10

    1 106465

    4 1

    1 317721

    1 460929

    1 644985

    1 84185

    1 89851

    6 81968

    1 492737

    5 493598

    Sample Output

    106465

    84185

    492737



    HINT

    1.n的数据范围:n<=100000
    2.每个数的数据范围:[-1e7,1e7]

    题意

     

    题解:

    用一个vector来做

    虽然感觉用set也行

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //无限大
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    //**************************************************************************************
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    
    vector<int> q;
    int main()
    {
        int t=read();
        while(t--)
        {
            int n=read(),m=read();
            if(n==1)
                q.insert(upper_bound(q.begin(),q.end(),m),m);
            if(n==2)
                q.erase(lower_bound(q.begin(),q.end(),m));
            if(n==3)
                printf("%d
    ",lower_bound(q.begin(),q.end(),m)-q.begin()+1);
            if(n==4)
                printf("%d
    ",q[m-1]);
            if(n==5)
                printf("%d
    ",*--lower_bound(q.begin(),q.end(),m));
            if(n==6)
                printf("%d
    ",*upper_bound(q.begin(),q.end(),m));
        }
    }
  • 相关阅读:
    Python shutil模块(目录和文件操作)
    CentOS8的web终端-cockpit
    OpenStack与ZStack深度对比:架构、部署、计算、运维监控等
    Zstack的安装部署
    Git介绍与简易搭建
    Docker 底层技术与端口映射
    Docker 网络
    Dockerfile编写
    Docker监控
    Docker 中卷组管理
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4442006.html
Copyright © 2020-2023  润新知