划分树---Feed the dogs】的更多相关文章

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,…
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…
                                                            Feed the dogs Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 20634   Accepted: 6494 Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed…
/************************************************************* 题目: Feed the dogs(poj 2761) 链接: http://poj.org/problem?id=2761 题意: 给一个数列,在给一些区间,求这些区间第k小的值,这些 区间没有包含关系,也就是说如果La>Lb那么Ra>Rb; 算法: treap树 思路: 由于这些区间没有包含关系,把这些区间排序后从左边 开始计算,每计算一个区间把前面多余数删除,这样…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 51732   Accepted: 17722 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
题意:给n个数,m次询问,每次询问L到R中第k小的数是哪个 算法1:划分树 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; ; ][mx]; int sortt[mx]; ][mx]; void build(int l,int r,int c) { if (l==r) return ; ; ; ; for (int i…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 47066   Accepted: 15743 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 35653   Accepted: 11382 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
Boring Counting Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述     In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence. Now you task is to answer a list of queries, for each…
题意:查询区间中位数 思路:模板题,相当于区间第K大的数,主席树可以水过,但划分树是正解.但还没搞明白划分树,先上模板 #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib> #include <string> #include <vector> #include <algorithm&g…
题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=4417 题目大意:给定一个区间,以及一个k值,求该区间内小于等于k值的数的个数.注意区间是从0开始的. 解题思路: 首先这题线段树可以解.方法是维护一个区间最大值max,一个区间点个数s,如果k>max,则ans=s+Q(rson),否则ans=Q(lson). 然后也可以用求区间第K大的划分树来解决,在对原来求第K大的基础上改改就行,方法如下: Build方法同第K大. 对于Query: ①左区…
题目链接 参考HH大神的模版.对其中一些转移,还没想清楚,大体明白上是怎么回事了,划分树就是类似快排,但有点点区别的.多做几个题,慢慢理解. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define N 100100 struct n…
//Accepted 14796 KB 453 ms //划分树 //把查询的次数m打成n,也是醉了一晚上!!! //二分l--r区间第k大的数和h比较 #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <cmath> #include <algorithm> using namespace std; /** * Thi…
//Accepted 28904 KB 781 ms //划分树 //所求x即为l,r区间排序后的中位数t //然后求出小于t的数的和sum1,这个可以用划分树做 //求出整个区间的和sum,可以用O(1)的数组做 //ans=(k-1)*t-sum1+sum-sum1-(l-r+1-k+1)*t #include <cstdio> #include <cstring> #include <iostream> #include <queue> #includ…
学习:http://www.cnblogs.com/pony1993/archive/2012/07/17/2594544.html 划分树的build: 划分树是分层构建的,在构建的t层时,我们可以得到第t层的num域,和分入左右孩子的元素 num域值该区间中从左到某个位置小于指定值的数的个数 查找可以看代码 //Accepted 28504 KB 1422 ms //划分树 #include <cstdio> #include <cstring> #include <io…
题意:给一个数组,每次询问输出在区间[L,R]之间小于H的数字的个数. 此题可以使用划分树在线解决. 划分树可以快速查询区间第K小个数字.逆向思考,判断小于H的最大的一个数字是区间第几小数,即是答案.这一步可以使用二分搜索上界.时间复杂度是O(logn*logn). #include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <algorithm&…
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2006 题意: 给出一个数列A,L,R,构造出一个新的集合,集合中的数字为A中任意连续t(L<=t<=R)个数字的和(集合中的数字可以重复).求集合中前K大的数字和. 思路:首先,我们令S[i]表示A的前i项和,P[i] 表示以A中第i个数字结尾可以取到的最大值,那么显然有: 求出P之后,我们可以用一个堆或者优先队列来维护最大值.那么现在来了另外一个问题,某次在优先队列中取得的是P[i…
题目链接:http://www.spoj.com/problems/PT07J/ 题意:给出一个有根树,1为根节点,每个节点有权值.若干询问,询问以u为根的子树中权值第K小的节点编号. 思路:DFS一次,记录每个节点在DFS序列中的开始和结束位置.那么以u为节点的子树的所有点都在两个u之间.那么询问就转化成询问区间的第K小值,可以将DFS序列建立划分树解决. #include <iostream>#include <cstdio>#include <string.h>#…
又是不带修改的区间第k大,这次用的是一个不同的方法,划分树,划分树感觉上是模拟了快速排序的过程,依照pivot不断地往下划分,然后每一层多存一个toleft[i]数组,就可以知道在这一层里从0到i里有多少个被划分到了左子树,知道区间有多少个被分到左子树,就可以一路递归下去,不需要像函数式线段数一样,二分再加query,所以每次询问的复杂度也只是O(nlogn),空间复杂度的话就是O(nlogn),具体的介绍很多个链接都有,具体看下面给出的两个链接,它们对我起到非常大的帮助. http://blo…
思路:裸的划分树 #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> #define Maxn 100010 #define lson(x) x<<1 #define rson(x) x<<1|1 using namespace std; ][Maxn],toLeft[][Maxn],sorte…
思路:裸的划分树 #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cstring> #define Maxn 100010 #define lson(x) x<<1 #define rson(x) x<<1|1 #define mid ((tree[po].l+tree[po].r)>>1) usi…
思路:裸的划分树 #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> #define Maxn 100010 #define inf 0x7fffffff #define lson(x) (x<<1) #define rson(x) ((x<<1…
思路:二分枚举区间第k大.用划分树查找是否符合要求的高度. #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cstring> #define Maxn 100010 #define lson(x) x<<1 #define rson(x) x<<1|1 #define mid ((tree[po].l+tree…
http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3237 Problem H:Boring Counting Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 8  Solved: 4 [Submit][Status][Discuss] Description In this problem you are given a number sequence P consisting of N int…
K-th Number Input The first line of the input file contains n --- the size of the array, and m --- the number of questions to answer (1 <= n <= 100 000, 1 <= m <= 5 000). The second line contains n different integer numbers not exceeding 109 b…
http://acm.hdu.edu.cn/showproblem.php?pid=2665 [ poj 2104 2761 ]  改变一下输入就可以过 http://poj.org/problem?id=2104 http://poj.org/problem?id=2761 Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submissio…
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 You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th order statistics in the array…
如果题目给出1e5的数据范围,,以前只会用n*log(n)的方法去想 今天学了一下两三种n*n*log(n)的数据结构 他们就是大名鼎鼎的 归并树 划分树 主席树,,,, 首先来说两个问题,,区间第k大 ,,,, 这个问题的通用算法是 划分树,, 说白一点就是把快速排序的中间结果存起来, 举个栗子 原数列 4 1 8 2 6 9 5 3 7 sorted 1 2 3 4 5 6 7 8 9 ........................... qs[0] 4 1 8 2 6 9 5 3 7 q…