hdu 2852 KiKi's K-Number
2014-08-03 22:27
197 查看
L - KiKi's K-Number
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
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!
询问的时候,(a,k)
对a+1,10 0000区间进行二分
getnum(x)得到是大于等于x数的个数
所以我们要找到getnum(a+1)-getnum(mid)==k
并且使得mid最小,最小的mid-1就是比a大的第k个数
好题!!!
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
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!
询问的时候,(a,k)
对a+1,10 0000区间进行二分
getnum(x)得到是大于等于x数的个数
所以我们要找到getnum(a+1)-getnum(mid)==k
并且使得mid最小,最小的mid-1就是比a大的第k个数
好题!!!
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<algorithm> #include<cstring> #include<stdlib.h> #include<string> #include<cmath> using namespace std; #define pb push_back int p[101010],m,mm; void update(int pos,int num){ while(pos>0){ p[pos]+=num; pos-=pos&(-pos); } } int getnum(int pos){ int sum=0; while(pos<=100000){ sum+=p[pos]; pos+=pos&(-pos); } return sum; } void Find(int pos,int k){ int l=pos+1,r=100000,mid,mm=10000000,be=getnum(pos+1); while(l<=r){ mid=(l+r)/2; int tmp=be-getnum(mid); if(tmp<k) l=mid+1; else{ mm=min(mm,mid-1); r=mid-1; } } if(mm!=10000000) printf("%d\n",mm); else printf("Not Find!\n"); } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r" ,stdin); #endif // ONLINE_JUDGE while(cin>>m){ memset(p,0,sizeof(p)); while(m--){ int a,b,c; scanf("%d",&a); if(a==0){ scanf("%d",&b); update(b,1); } if(a==1){ scanf("%d",&b); if(getnum(b)-getnum(b+1)>0) update(b,-1); else printf("No Elment!\n"); } if(a==2){ scanf("%d%d",&b,&c); Find(b,c); } } } }
相关文章推荐
- hdu 2852 KiKi's K-Number
- HDU 2852 KiKi's K-Number
- hdu 2852 KiKi's K-Number (线段树,求大于x的第k小数)
- HDU 2852 KiKi's K-Number (主席树)
- HDU 2852 KiKi's K-Number(树状数组+二分搜索)
- HDU 2852 KiKi's K-Number 树状数组 + 二分
- HDU 2852 KiKi's K-Number(离线+树状数组)
- HDU 2852 KiKi's K-Number 主席树
- HDU 2852 KiKi's K-Number
- HDU 2852 KiKi's K-Number【 树状数组 二分 】
- HDU 2852 KiKi's K-Number 树状数组
- HDU - 2852 - KiKi's K-Number(树状数组)
- HDU 2852 KiKi's K-Number 树状数组
- HDUOJ-----2852 KiKi's K-Number(树状数组+二分)
- HDU 2852 KiKi's K-Number (树状数组+二分)
- HDU 2852-KiKi's K-Number(线段树)
- hdu2852——KiKi's K-Number
- HDU 2852 KiKi's K-Number(树状数组+二分)
- hdu 2852 KiKi's K-Number
- hdu2852--KiKi's K-Number(线段树,求第k个数)