hdu 3473 (划分树)2】的更多相关文章

Minimum Sum Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3611    Accepted Submission(s): 829 Problem Description You are given N positive integers, denoted as x0, x1 ... xN-1. Then give you…
题目链接:  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: ①左区…
思路:裸的划分树 #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…
Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory. Now the poor princess is in trouble again and Mario needs to save his lover. We regard the road to the boss’s castle as a line (…
题意:有n个数.m个询问(l,r,k),问在区间[l,r] 有多少个数小于等于k. 划分树--查找区间第k大的数.... 利用划分树的性质.二分查找在区间[l,r]小于等于k的个数. 假设在区间第 i 大的数tmp>k,则往下找,假设tmp<k,往上找.   #include<cstdio> #include<stdlib.h> #include<string.h> #include<string> #include<map> #in…
Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6951    Accepted Submission(s): 2214 Problem Description Give you a sequence and ask you the kth big number of a inteval.   Input The…
http://acm.hdu.edu.cn/showproblem.php?pid=3473 划分树模板题目,需要注意的是划分树的k是由1开始的 划分树: 参考:http://blog.csdn.net/shiqi_614/article/details/8041390 划分树的定义 划分树定义为,它的每一个节点保存区间[lft,rht]所有元素,元素顺序与原数组(输入)相同,但是,两个子树的元素为该节点所有元素排序后(rht-lft+1)/2个进入左子树,其余的到右子树,同时维护一个num域,…
题意:给定一个数组,有Q次的询问,每次询问的格式为(l,r),表示求区间中一个数x,使得sum = sigma|x - xi|最小(i在[l,r]之间),输出最小的sum. 思路:本题一定是要O(nlogn)或更低复杂度的算法.首先很容易得出这个x的值一定是区间(l,r)的中位数的取值,排序之后,也就是假设区间(l,r)长度为len ,则中位数就是该区间的第(r - l) / 2 - 1小的元素,求一个区间的第K小元素的算法很自然地会想到划分树, 而且划分树的查询复杂度为:O(logn),正好可…