KiKi's K-Number

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 211 Accepted Submission(s): 88
 
Problem Description
For the k-th number, we all should be very familiar with it. Of course,to kiki it is also simple. Now Kiki meets a very similar problem, kiki wants to design a container, the container is to support the three operations.

Push: Push a given element e to container

Pop: Pop element of a given e from container

Query: Given two elements a and k, query the kth larger number which greater than a in container;

Although Kiki is very intelligent, she can not think of how to do it, can you help her to solve this problem?

 
Input
Input some groups of test data ,each test data the first number is an integer m (1 <= m <100000), means that the number of operation to do. The next m lines, each line will be an integer p at the beginning, p which has three values:
If p is 0, then there will be an integer e (0 <e <100000), means press element e into Container.

If p is 1, then there will be an integer e (0 <e <100000), indicated that delete the element e from the container

If p is 2, then there will be two integers a and k (0 <a <100000, 0 <k <10000),means the inquiries, the element is greater than a, and the k-th larger number.

 
Output
For each deletion, if you want to delete the element which does not exist, the output "No Elment!". For each query, output the suitable answers in line .if the number does not exist, the output "Not Find!".
 
Sample Input
5
0 5
1 2
0 6
2 3 2
2 8 1
7
0 2
0 2
0 4
2 1 1
2 1 2
2 1 3
2 1 4
 
Sample Output
No Elment!
6
Not Find!
2
2
4
Not Find!
 
 
Source
2009 Multi-University Training Contest 4 - Host by HDU
 
Recommend
gaojie
/*
树状数组基本应用,查询的时候用二分,二分少了一个等号wa了一下午真心心累
*/
#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define N 100005
using namespace std;
int c[N];
int build(int x,int val)//包括存元素,删元素
{
while(x<N)
{
c[x]+=val;
x+=lowbit(x);
}
}
int findx(int x)
{
int cur=;
while(x>)
{
cur+=c[x];
x-=lowbit(x);
}
return cur;
}
int queuy(int p,int k)
{
int l=p+,r=N-,mid,m;
int now=findx(p);
int flag=-;
while(l<=r)
{
//cout<<"l="<<l<<" r="<<r<<endl;
m=(l+r)/;
mid=findx(m)-now;
if(mid>=k&&findx(m-)-now<k)//敲好找到元素个数是k的
{
flag=m;
break;
}
else if(mid<k)
l=m+;
else
r=m-;
}
return flag;
}
int n,op,a,b;
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
while(scanf("%d",&n)!=EOF)
{
memset(c,,sizeof c);
for(int ca=;ca<n;ca++)
{
scanf("%d",&op);
if(op==)
{
scanf("%d",&a);
build(a,);
}
else if(op==)
{
scanf("%d",&a);
int s=findx(a)-findx(a-);//判断这个位置是不是有数
if(s==)
puts("No Elment!");
else
build(a,-);
}
else if(op==)
{
scanf("%d%d",&a,&b);
int s=queuy(a,b);
if(s==-)
puts("Not Find!");
else
printf("%d\n",s);
}
}
}
return ;
}

KiKi's K-Number的更多相关文章

  1. 2019牛客网暑假多校训练第四场 K —number

    链接:https://ac.nowcoder.com/acm/contest/884/K来源:牛客网 题目描述 300iq loves numbers who are multiple of 300. ...

  2. 2019牛客暑期多校训练营(第四场)K.number

    >传送门< 题意:给你一个字符串s,求出其中能整除300的子串个数(子串要求是连续的,允许前面有0) 思路: >动态规划 记f[i][j]为右端点满足mod 300 = j的子串个数 ...

  3. 2019牛客暑期多校训练营(第四场) - K - number - dp

    https://ac.nowcoder.com/acm/contest/884/K 一开始整了好几个假算法,还好测了一下自己的样例过了. 考虑到300的倍数都是3的倍数+至少两个零(或者单独的0). ...

  4. 2019牛客多校第四场K number dp or 思维

    number 题意 给一个数字串,问有几个子串是300的倍数 分析 dp写法:这题一看就很dp,直接一个状态dp[i][j]在第i位的时候膜300的余数是j左过去即可.这题比赛的时候样例老是少1,后面 ...

  5. 2019牛客多校训练第四场K.number(思维)

    题目传送门 题意: 输入一个只包含数字的字符串,求出是300的倍数的子串的个数(不同位置的0.00.000等都算,并考虑前导零的情况). sample input: 600 1230003210132 ...

  6. K number(思维和后缀以及3的特性)(2019牛客暑期多校训练营(第四场))

    示例1: 输入:600 输出:4 说明:'600', '0', '0', '00' are multiples of 300. (Note that '0' are counted twice bec ...

  7. [LeetCode] Top K Frequent Elements 前K个高频元素

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  8. (Collection)347. Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  9. Leetcode 347. Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  10. 347. Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

随机推荐

  1. CSS3 animation-timing-function steps()

    animation-timging-function 主要是控制css动画从开始到结束的速度. linear:线性过渡.等同于贝塞尔曲线(0.0, 0.0, 1.0, 1.0) ease:平滑过渡.等 ...

  2. Sql Server——数据的增删改

    所谓数据的增删改就是在创建好数据库和表后向表中添加数据.删除表中的数据.更改表中的一些数据. 新增数据: 语法一: insert into 表名 values (数据内容)        --这里需要 ...

  3. 浅析强连通分量(Tarjan和kosaraju)

    理解   在有向图G中,如果两点互相可达,则称这两个点强连通,如果G中任意两点互相可达,则称G是强连通图. 定理: 1.一个有向图是强连通的,当且仅当G中有一个回路,它至少包含每个节点一次.     ...

  4. mxnet的训练过程——从python到C++

    mxnet的训练过程--从python到C++ mxnet(github-mxnet)的python接口相当完善,我们可以完全不看C++的代码就能直接训练模型,如果我们要学习它的C++的代码,从pyt ...

  5. CentOS7 + Nginx1.13.5 + PHP7.1.10 + MySQL5.7.19 源码编译安装

    一.安装Nginx 1.安装依赖扩展 # yum -y install wget openssl* gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng ...

  6. Android shared_preference操作

    实例化SharedPreferences对象 //test :想要打开的SharedPreferences文件名 //Activity.MODE_PRIVATE:操作模式 MODE_PRIVATE | ...

  7. gulp使用1-入门指南

    入门指南 1. 全局安装 gulp: $ npm install --global gulp 或使用cnpm 2. 作为项目的开发依赖(devDependencies)安装: $ npm instal ...

  8. Ubuntu 14.04 安装 Sublime Text 3

    1. 实验环境 Ubuntu 14.04 + Sublime text 3 2. sublime text介绍 ublime Text 是一款流行的文本编辑器软件,有点类似于TextMate,跨平台, ...

  9. 关于Android SDK Manager无法获取更新列表的正确设置

    1.以"管理员身份运行"SDK Manager. 2.Android SDK Manager"=>"Tools"=>"Optio ...

  10. 使用jquery-qrcode在页面上生成二维码,支持中文

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...