HDU_2665 Kth number[可持续化线段树]
来源:互联网 发布:淘宝数字油画 编辑:程序博客网 时间:2024/05/17 08:54
传送门:HDU_2665
Kth number
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
题意:求区间第K大树。
思路:可持续化线段树。
代码:
/************************************************* Author: Ac_sorry* File:* Create Date:* Motto: One heart One life* CSDN: http://blog.csdn.net/code_or_code*************************************************/#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<cstdlib>#include<vector>#include<string>#include<map>#include<utility>#include<queue>#include<stack>#define INF 0x3f3f3f3f#define MOD 1000000007#define seed_ 131#define eps 1e-8#define mem(a,b) memset(a,b,sizeof a)#define w(p) tree[p].w#define ls(p) tree[p].ls#define rs(p) tree[p].rsusing namespace std;typedef long long LL;const int N=100010;int a[N],b[N];int root[N],sz;struct node{ int ls,rs; int w; node(){ls=rs=w=0;}}tree[N*20];void update(int &i,int l,int r,int x){ tree[++sz]=tree[i];i=sz; w(i)++; if(l==r) return; int m=(l+r)>>1; if(x<=m) update(ls(i),l,m,x); else update(rs(i),m+1,r,x);}int query(int i,int j,int l,int r,int k){ if(l==r) return l; int t=w(ls(j))-w(ls(i)); int m=(l+r)>>1; if(t>=k) return query(ls(i),ls(j),l,m,k); else return query(rs(i),rs(j),m+1,r,k-t);}int main(){ int T_;scanf("%d",&T_); //int AC=0; while(T_--) { root[0]=0; sz=0; int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",a+i); b[i]=a[i]; } sort(b+1,b+1+n); int cnt=unique(b+1,b+1+n)-(b+1); int mpp; for(int i=1;i<=n;i++) { root[i]=root[i-1]; mpp=lower_bound(b+1,b+1+cnt,a[i])-b; update(root[i],1,cnt,mpp); } int l,r,k; for(int i=0;i<m;i++) { scanf("%d%d%d",&l,&r,&k); int pos=query(root[l-1],root[r],1,cnt,k); printf("%d\n",b[pos]); } } return 0;}
0 0
- HDU_2665 Kth number[可持续化线段树]
- Kth number (HDU_2665) 划分树
- HDU 2665 Kth number(可持续化线段树)
- 可持续化线段树
- hdu2665 可持续化线段树
- hdu2665 可持续化线段树
- HDU2665 Kth number 可持久化线段树
- hdu 2665 Kth number ( 可持久化线段树 )
- hdu 2665 Kth number(函数化线段树)
- HDU 2665 Kth number 可持久化线段树
- HDU-2665 Kth number (可持久化线段树)
- HDU 2665 Kth number 可持久化线段树
- BZOJ3673 & BZOJ3674 可持续化并查集 【可持续化线段树维护可持续化数组】
- 主席树(可持续化线段树)
- hdu 4348 可持续化线段树
- HDU2665 kth number 线段树做法
- [NOI2010]超级钢琴(可持续化线段树)
- [POJ2104/HDU2665]Kth Number-主席树-可持久化线段树
- django model 聚合
- xcode运行模拟器时出现问题 (Domain = FBSOpenApplicationErrorDomain, Code = 4)
- Python http访问学习
- c++字符串详解
- keepalived仅实现HA
- HDU_2665 Kth number[可持续化线段树]
- SGU - 123 - The sum (简单数学!)
- R语言绘制箱线图
- linux网络编程之socket(十三):epoll 系列函数简介、与select、poll 的区别
- php面向对象_get(),_set()的用法
- NSFileManager操作2
- Gradle构建项目小技巧
- ceph存储 ceph-fuse源码分析一
- MysqlExplain详解