SBT的应用——求区间第k值——poj2761
2011-01-22 17:40
162 查看
[b] Feed the dogs[/b]
Description
Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs every day for Wind. Jiajia loves Wind, but not the dogs, so Jiajia use a special way to feed the dogs. At lunchtime, the dogs will stand on one line, numbered from 1 to n, the leftmost one is 1, the second one is 2, and so on. In each feeding, Jiajia choose an inteval[i,j], select the k-th pretty dog to feed. Of course Jiajia has his own way of deciding the pretty value of each dog. It should be noted that Jiajia do not want to feed any position too much, because it may cause some death of dogs. If so, Wind will be angry and the aftereffect will be serious. Hence any feeding inteval will not contain another completely, though the intervals may intersect with each other.
Your task is to help Jiajia calculate which dog ate the food after each feeding.
Input
The first line contains n and m, indicates the number of dogs and the number of feedings.
The second line contains n integers, describe the pretty value of each dog from left to right. You should notice that the dog with lower pretty value is prettier.
Each of following m lines contain three integer i,j,k, it means that Jiajia feed the k-th pretty dog in this feeding.
You can assume that n<100001 and m<50001.
Output
Output file has m lines. The i-th line should contain the pretty value of the dog who got the food in the i-th feeding.
Sample Input
Sample Output
题目大意:给定n个数值,给定m个区间和m个对应的k值,求这个区间的第k大值。我们可以采用这种方法:因为要求m个区间的第k大值,如果考虑到使用平衡树,那么必须保证总的效率是O(NlogN)。既然区间不会有重合的地方,我们就可以采用离散化的方式,将m个区间排序,这是可以保证后面的一个区间要么不包括前面的区间,要么有一部分重合,对于重合我们不必重新插入数据,这样可以保证每一个数据最多被插入一次、删除一次。
这里采用的是CQF大牛的SBT,当然可以采用线段树或者树状数组,这里不作介绍。
如果对于SBT不太了解,请:/article/5730023.html
Time Limit: 6000MS | Memory Limit: 65536K | |
Total Submissions: 5092 | Accepted: 1348 |
Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs every day for Wind. Jiajia loves Wind, but not the dogs, so Jiajia use a special way to feed the dogs. At lunchtime, the dogs will stand on one line, numbered from 1 to n, the leftmost one is 1, the second one is 2, and so on. In each feeding, Jiajia choose an inteval[i,j], select the k-th pretty dog to feed. Of course Jiajia has his own way of deciding the pretty value of each dog. It should be noted that Jiajia do not want to feed any position too much, because it may cause some death of dogs. If so, Wind will be angry and the aftereffect will be serious. Hence any feeding inteval will not contain another completely, though the intervals may intersect with each other.
Your task is to help Jiajia calculate which dog ate the food after each feeding.
Input
The first line contains n and m, indicates the number of dogs and the number of feedings.
The second line contains n integers, describe the pretty value of each dog from left to right. You should notice that the dog with lower pretty value is prettier.
Each of following m lines contain three integer i,j,k, it means that Jiajia feed the k-th pretty dog in this feeding.
You can assume that n<100001 and m<50001.
Output
Output file has m lines. The i-th line should contain the pretty value of the dog who got the food in the i-th feeding.
Sample Input
7 2 1 5 2 6 3 7 4 1 5 3 2 7 1
Sample Output
3 2
题目大意:给定n个数值,给定m个区间和m个对应的k值,求这个区间的第k大值。我们可以采用这种方法:因为要求m个区间的第k大值,如果考虑到使用平衡树,那么必须保证总的效率是O(NlogN)。既然区间不会有重合的地方,我们就可以采用离散化的方式,将m个区间排序,这是可以保证后面的一个区间要么不包括前面的区间,要么有一部分重合,对于重合我们不必重新插入数据,这样可以保证每一个数据最多被插入一次、删除一次。
of longint]
这里采用的是CQF大牛的SBT,当然可以采用线段树或者树状数组,这里不作介绍。
如果对于SBT不太了解,请:/article/5730023.html
相关文章推荐
- poj2104&&poj2761 (主席树&&划分树)主席树静态区间第k大模板
- hdu2665/poj2104;poj2761 区间第k小 函数式线段树
- [POJ2761]Feed the dogs(静态区间第k小,主席树)
- poj2761(静态区间第k大,treap)
- POJ2761---Feed the dogs (Treap求区间第k大)
- POJ2104 POJ2761 区间第K大 主席树
- POJ2104 K-th Number (子区间内第k大的数字)【划分树算法模板应用】
- 【POJ2761】【区间第k大】Feed the dogs(吐槽)
- ZOJ 2112 Dynamic Rankings (动态区间第K大) (线段树套SBT+二分)
- HDU3727--Jewel (主席树 静态区间第k大)
- HDU 2665 求静态区间的第k小值 主席树讲解。
- poj 2104 K-th Number 区间第K大 二分 离散化 + (莫队 树状数组/平方分解/线段树)
- 51nod 1686 第K大区间(二分 尺取)
- POJ 2761 Feed the dogs 主席树(区间第k大)
- 主席树-区间第k大值(不带修改)
- 快排划分思想的应用-求第k大数或者第k小的数(求前k大数或者前k小的数)
- ZOJ 2112 Dynamic Rankings 动态区间第k大 分块
- 求第k大连续区间和/第k大子序列和 - 二分+树状数组+前缀和(或主席树+堆)
- noip模拟赛 第k大区间
- zoj2112 动态区间第k大【整体二分】