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 ...
随机推荐
- Numpy中Meshgrid函数介绍及2种应用场景
近期在好几个地方都看到meshgrid的使用,虽然之前也注意到meshgrid的用法.但总觉得印象不深刻,不是太了解meshgrid的应用场景.所以,本文将进一步介绍Numpy中meshgrid的用法 ...
- RMQ-ST算法的理解与实现(C++)
RMQ-ST的含义 RMQ(Range Minimum/Maximum Query),即区间最值查询,是指这样一个问题:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j<=n),返 ...
- 基于React Native的移动平台研发实践分享
转载:http://blog.csdn.net/haozhenming/article/details/72772787 本文目录: 一.React Native 已经成为了移动前端技术的趋势 二.基 ...
- python文件名和文件路径操作
Readme: 在日常工作中,我们常常涉及到有关文件名和文件路径的操作,在python里的os标准模块为我们提供了文件操作的各类函数,本文将分别介绍"获得当前路径""获得 ...
- java从命令行接收多个数字,求和程序分析
问题:编写一个程序,此程序从命令行接收多个数字,求和之后输出结果. 1.设计思想 (1)声明两个变量接收输入的字符串 (2)将字符串转换成int类型 (3)输出求和 2.程序流程图 3.源程序代码 i ...
- MyBatis注解select in参数
/** * * @param ids '1,2,3' * @return */ @Select("select * from user_info where id in (${ids})& ...
- OpenVPN CentOS7 安装部署配置详解
一 .概念相关 1.vpn 介绍 vpn 虚拟专用网络,是依靠isp和其他的nsp,在公共网络中建立专用的数据通信网络的技术.在vpn中任意两点之间的链接并没有传统的专网所需的端到端的物理链路,而是利 ...
- HDU1421搬寝室(简单DP)
当然,还可以加滚动数组优化. #include<cstdio> #include<cstdlib> #include<iostream> #include<m ...
- RESTful API 架构解读
RESTful API 架构解读 首先我们还是先介绍下 RESTful api 的来龙去脉. 首先, RESTful (下文都简称 RESTful api 为 RESTful ) 1.RESTful ...
- pb9常见错误及含义
1. by zero 发生被0除错误 2. Null object reference 空对象引用 3. Array boundary exceeded 数组越界 4. Enumerated v ...