Poj2761-Feed the dogs(伸展树求名次)】的更多相关文章

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,…
/************************************************************* 题目: Feed the dogs(poj 2761) 链接: http://poj.org/problem?id=2761 题意: 给一个数列,在给一些区间,求这些区间第k小的值,这些 区间没有包含关系,也就是说如果La>Lb那么Ra>Rb; 算法: treap树 思路: 由于这些区间没有包含关系,把这些区间排序后从左边 开始计算,每计算一个区间把前面多余数删除,这样…
Desciption 题意:求区间第K小(N<=100000) Solution 主席树模板题 Code #include <cstdio> #include <algorithm> #define N 100010 using namespace std; int n,m,A[N],rank[N],T[N],ls[N*20],rs[N*20],sum[N*20],tot; inline int read(){ int x=0,f=1;char ch=getchar(); w…
先用莫队算法保证在询问之间转移的复杂度,每次转移都需要进行O(sqrt(m))次插入和删除,权值分块的插入/删除是O(1)的. 然后询问的时候用权值分块查询区间k小值,每次是O(sqrt(n))的. 所以总共的复杂度是O(m*(sqrt(n)+sqrt(m)))的. 常数极小. 别的按权值维护的数据结构无法做到O(1)地插入删除. poj2104 的输出优化 别忘了处理负数. 完爆主席树,这份代码目前在 poj2761 上 Rank1. Rank Run ID User Memory Time…
题目链接:http://poj.org/problem?id=2761 题目大意:给你n个数,m次查询,m次查询分别是a,b,k,查询下表从a到b的第k小元素是哪个.这m个区间不会互相包含. Treap,自己学着写了个板子,留贴备用. 离线操作,将区间移动之,删除旧的添加新的. #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <ma…
Problem 查询区间第k大,但保证区间不互相包含(可以相交) Solution 只需要对每个区间左端点进行排序,那它们的右端点必定单调递增,不然会出现区间包含的情况. 所以我们暴力对下一个区间加上这个区间没有的点,删去下个区间没有的点. 因为每个点最多被加入,删除1次,所以时间复杂度为O(nlogn) Notice 当相邻两段区间不相交时,那么我们要先加入点,在删去点. Code 非旋转Treap #include<cmath> #include<cstdio> #includ…
Feed the dogs Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 16860   Accepted: 5273 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…
POJ  2761 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…
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,…
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,…