KiKi's K-Number
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 |
|
Sample Output
No Elment! |
|
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的更多相关文章
- 2019牛客网暑假多校训练第四场 K —number
链接:https://ac.nowcoder.com/acm/contest/884/K来源:牛客网 题目描述 300iq loves numbers who are multiple of 300. ...
- 2019牛客暑期多校训练营(第四场)K.number
>传送门< 题意:给你一个字符串s,求出其中能整除300的子串个数(子串要求是连续的,允许前面有0) 思路: >动态规划 记f[i][j]为右端点满足mod 300 = j的子串个数 ...
- 2019牛客暑期多校训练营(第四场) - K - number - dp
https://ac.nowcoder.com/acm/contest/884/K 一开始整了好几个假算法,还好测了一下自己的样例过了. 考虑到300的倍数都是3的倍数+至少两个零(或者单独的0). ...
- 2019牛客多校第四场K number dp or 思维
number 题意 给一个数字串,问有几个子串是300的倍数 分析 dp写法:这题一看就很dp,直接一个状态dp[i][j]在第i位的时候膜300的余数是j左过去即可.这题比赛的时候样例老是少1,后面 ...
- 2019牛客多校训练第四场K.number(思维)
题目传送门 题意: 输入一个只包含数字的字符串,求出是300的倍数的子串的个数(不同位置的0.00.000等都算,并考虑前导零的情况). sample input: 600 1230003210132 ...
- K number(思维和后缀以及3的特性)(2019牛客暑期多校训练营(第四场))
示例1: 输入:600 输出:4 说明:'600', '0', '0', '00' are multiples of 300. (Note that '0' are counted twice bec ...
- [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 ...
- (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 ...
- 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 ...
- 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 ...
随机推荐
- CentOS7的一些初始化
默认最小化安装 [root@GVMCET001 ~]# nmtui 设置网络,主机名等 [root@GVMCET001 ~]# yum update 更新系统 SSH [root@GVMCET001 ...
- ActiveMQ 入门helloworld
1.下载安装ActiveMQ 官网下载地址:http://activemq.apache.org/download.html ActiveMQ 提供了Windows 和Linux.Unix 等几个版本 ...
- 初次就这么给了你(Django-rest-framework)
Django-Rest-Framework Django-Rest框架是构建Web API强大而灵活的工具包. 简单粗暴,直奔主题. pip install django pip install dj ...
- HTML5可预览多图片ajax上传(使用formData传递数据)
HTML5可预览多图片ajax上传(使用formData传递数据) 在介绍上传图片之前,我们简单的来了解下FormData的基本使用:介绍完成后这些基本知识后,我们会在文章最后提供一个demo,就是a ...
- Java 数组扩容
在添加数据到达数组的上限的时候数组进行扩容: public void resizeArrayCaptcity(){ if(size>=arr.length){ Emp [] arr2=new ...
- uva1267 Network
https://vjudge.net/problem/UVA-1267 题意: 有一棵树,上面有一个放着水源的点s,给出一个数k,这个水源可以覆盖路径长度到s不超过k的叶子节点.现在需要把所有的叶子节 ...
- bzoj4557【JLOI2016】侦查守卫
这道题对于我来说并不是特别简单,还可以. 更新一下blog 树形DP f[i][j]表示i的子树中,最高覆盖到i向下第j层的最小花费. g[i][j]表示i的子树全部覆盖,还能向上覆盖j层的最小花费. ...
- 兼容低版本JS的Array.map方法
前几天去别的公司面试遇到个这样的问题,兼容IE7下的Array.map方法,一脸蒙蔽.后面回来查了下资料发现.Array.map方法是ECMA-262 标准中新添加的方法,在低版本的JS中是木有的. ...
- Oracle的常用命令之备份和恢复数据库
1 将数据库TES完全导出,用户名system 密码manager 导出到D:\daochu.dmp中 exp system/manager@TEST file=d:\daochu.dmp 2 将数据 ...
- 手动打包MVC项目成Web Deploy包,发布至服务器
①确保服务器上安装了Web Deploy,可以使用微软Web Paltform Installer安装.https://www.microsoft.com/web/downloads/platform ...