HDU2665-Kth number
来源:互联网 发布:饥荒数据修改 编辑:程序博客网 时间:2024/06/07 04:36
Kth number
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9899 Accepted Submission(s): 3070
Problem Description
Give you a sequence and ask you the kth big number of a inteval.
Input
The first line is the number of the test cases.
For each test case, the first line contain two integer n and m (n, m <= 100000), indicates the number of integers in the sequence and the number of the quaere.
The second line contains n integers, describe the sequence.
Each of following m lines contains three integers s, t, k.
[s, t] indicates the interval and k indicates the kth big number in interval [s, t]
For each test case, the first line contain two integer n and m (n, m <= 100000), indicates the number of integers in the sequence and the number of the quaere.
The second line contains n integers, describe the sequence.
Each of following m lines contains three integers s, t, k.
[s, t] indicates the interval and k indicates the kth big number in interval [s, t]
Output
For each test case, output m lines. Each line contains the kth big number.
Sample Input
1 10 1 1 4 2 3 5 6 7 8 9 0 1 3 2
Sample Output
2
Source
HDU男生专场公开赛——赶在女生之前先过节(From WHU)
题意:给出n个数,有m个询问,求区间内第k大的数是哪个
解题思路:由于题目未说明n个数的范围,因此可以先做一个预处理,将n个数排序后重新编号,然后建一棵可持久化线段树来维护
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <set>using namespace std;#define LL long longint n,m,k;int a[100009],x[100009];int s[100009],L[100009*20],R[100009*20],sum[100009*20];int tot;void build(int now,int l,int r,int p){ sum[++tot]=sum[now]+1; if(l==r) L[tot]=R[tot]=0; else { int mid=(l+r)>>1; L[tot]=L[now];R[tot]=R[now]; if(mid>=p) L[tot]=tot+1; else R[tot]=tot+1; if(p<=mid) build(L[now],l,mid,p); else build(R[now],mid+1,r,p); }}int query(int u,int v,int l,int r,int p){ if(l==r) return l; else { int mid=(l+r)>>1; if(p>sum[L[u]]-sum[L[v]]) return query(R[u],R[v],mid+1,r,p-sum[L[u]]+sum[L[v]]); else return query(L[u],L[v],l,mid,p); }}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d %d",&n,&k); for(int i=1;i<=n;i++) scanf("%d",&a[i]),x[i]=a[i]; sort(a+1,a+n+1); m=unique(a+1,a+n+1)-a; memset(s,0,sizeof s); L[0]=R[0]=sum[0]=tot=0; for(int i=1;i<=n;i++) { x[i]=lower_bound(a+1,a+m,x[i])-a; s[i]=tot+1; build(s[i-1],1,m,x[i]); } int ll,rr,kk; for(int i=0;i<k;i++) { scanf("%d %d %d",&ll,&rr,&kk); printf("%d\n",a[query(s[rr],s[ll-1],1,m,kk)]); } } return 0;}
0 0
- hdu2665-Kth number
- HDU2665-Kth number
- HDU2665 Kth number
- HDU2665 Kth number 【归并树】
- 主席树 hdu2665 Kth number
- HDU2665--Kth Number(划分树)
- [hdu2665 Kth number]区间第k大数
- HDU2665 Kth number(主席树入门)
- HDU2665 kth number 线段树做法
- HDU2665-主席树&模板-Kth number
- hdu2665 Kth number(主席树模板)
- POJ2104 hdu2665 主席树入门 Kth-number
- (主席树)hdu2665 Kth number
- HDU2665 Kth number 可持久化线段树
- HDU2665 Kth number(区间第K大)
- HDU2665 Kth number(划分树模板题)
- [POJ2104/HDU2665]Kth Number-主席树-可持久化线段树
- poj2104&HDU2665 K-th number
- 如何调到下一个页面点击按钮、刚学习不太懂、希望大虾们帮忙
- 简单工厂模式
- Java Swing基础
- JS中关于clientWidth offsetWidth scrollWidth等的一些含义
- 程序员必知的8大排序(三)-------冒泡排序,快速排序(java实现)
- HDU2665-Kth number
- RESTful API接口设计
- IOS 改变键盘颜色的代码
- Thread.interrupted()与Thread.isInterrupted()的区别
- AES加解密
- Java 集合(续)
- eclipse中建立源码存在的文件目录
- Java JDBC
- SpringMVC form表单提交list对象集合