zoukankan      html  css  js  c++  java
  • K-集合 (JXNU第二次周赛1006)set/平衡树

    K-集合

    Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
    Total Submission(s) : 2   Accepted Submission(s) : 1

    Font: Times New Roman | Verdana | Georgia

    Font Size: ← →

    Problem Description

    K-集合是一个这样的集合,它能够维护一些数,并可以迅速获取所有数里面第K大的数。
    一开始,K-集合为空。接下来有三种操作。第一种操作是Insert x,表示将数x插入到集合中去。第二种操作是Query k,表示查询这个集合里面所有数中第K大的数,如果不存在,则输出-1。第三种操作是Delete k,表示删除所有数中第K大的那个数,如果不存在,则不用删除。为了简单起见,对于,每一个插入的数均不相同。

    Input

    输入包括多组测试数据,大概5组,每组数据第一行是一个整数n(1<=n<=100000);代表接下来有n个操作,每个操作占一行。
    操作格式为:Insert x(1<=x<=1000000)or Query k(1<=k<=100000) or Delete k(1<=k<=100000)

    Output

    对于每一个询问,输出这个集合里面所有数中第K大的数,如果不存在,则输出-1。每个结果占一行。

    Sample Input

    6
    Query 1
    Insert 1
    Insert 2
    Query 2
    Delete 2
    Query 1

    Sample Output

    -1
    1
    2

    Author

    吴迎
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <queue>
    #include <typeinfo>
    #include <map>
    #include<bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    #define inf 10000000
    inline ll read()
    {
        ll 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;
    }
    //***************************************************************
    
    vector<int >v;
    int n;
    char a[111];
    int main()
    {
    
        while(cin>>n)
        {
            v.clear();
            for(int i=1;i<=n;i++){
                int x;
                scanf("%s%d",a,&x);
                if(a[0]=='Q')
                {
                    if(v.size()<x)puts("-1");
                    else {
                        cout<<v[v.size()-x]<<endl;
                    }
                }
                else if(a[0]=='I')
                {
                    v.insert(lower_bound(v.begin(),v.end(),x),x);
                }
                else {
                        if(v.size()<x)continue;
                    v.erase(lower_bound(v.begin(),v.end(),v[v.size()-x]));
                }
    
            }
           // for(int j=0;j<v.size();j++)cout<<v[j]<<endl;
        }
        return 0;
    }

    平衡树就算了

  • 相关阅读:
    XDebug的配置和使用
    PHP一致性hash
    命令注入绕过技巧总结
    Aireplay-ng 6 种常用攻击模式详解
    CDlinux无线审计工具使用
    Aircrack-ng无线审计工具使用
    Ubuntu中的mysql
    Centos安装python3.7时遇到的问题
    写程序的时候发现了个数学在线工具,感觉挺好,Gegebra
    OpenCV实现图像变换(python)-仿射变换原理
  • 原文地址:https://www.cnblogs.com/zxhl/p/4731211.html
Copyright © 2011-2022 走看看