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 ...
随机推荐
- 在 macOS High Sierra 10.13 搭建 PHP 开发环境
2017 年 9 月 26 日,苹果公司正式发布了新一代 macOS,版本为 High Sierra (11.13). macOS High Sierra 预装了 Ruby(2.3.3).PHP(7. ...
- 云计算之openstack ocata 项目搭建详细方法
之前写过一篇<openstack mitaka 配置详解>然而最近使用发现阿里不再提供m版本的源,所以最近又开始学习ocata版本,并进行总结,写下如下文档 OpenStack ocata ...
- 深入理解计算机系统chapter8
进程轮流使用处理器 父进程调用fork来创建一个新的子进程 回收子进程 waitpid/wait 非本地跳转:
- 关于js浮点数计算精度不准确问题的解决办法
今天在计算商品价格的时候再次遇到js浮点数计算出现误差的问题,以前就一直碰到这个问题,都是简单的使用tofixed方法进行处理一下,这对于一个程序员来说是及其不严谨的.因此在网上收集了一些处理浮点数精 ...
- 随机算法 poj 2576 Tug of War
Tug of War Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8187 Accepted: 2204 Descri ...
- CodeForces 242E二维线段树
E. XOR on Seg ...
- 最长回文 hdu3068(神代码)
最长回文 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- webpack2使用ch5-多页面设置 内部js和引入js
1 当前目录 2 webpack.config.js 配置 const webpack = require('webpack'), htmlWebpackPlugin = require('html- ...
- 让asp.net网站支持多语言,使用资源文件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs&quo ...
- 使用beanstalkd实现定制化持续集成过程中pipeline
持续集成是一种项目管理和流程模型,依赖于团队中各个角色的配合.各个角色的意识和配合不是一朝一夕能练就的,我们的工作只是提供一种方案和能力,这就是持续集成能力的服务化.而在做持续集成能力服务化的过程中, ...