裸的区间第k大问题,划分树搞起. #pragma comment(linker, "/STACK:10240000") #include <map> #include <set> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <vector> #inc…
看到好多讲解都把整体二分和$CDQ$分治放到一起讲 不过自己目前还没学会$CDQ$分治 就单独谈谈整体二分好了 先推荐一下$XHR$的 <浅谈数据结构题的几个非经典解法> 整体二分在当中有较为详细的讲解 先来说一下静态第$K$小的整体二分解法 $(POJ2104)$ 题目链接:http://poj.org/problem?id=2104 所谓整体二分 就是利用所有的询问相互独立而把它们$($此题没有修改操作$)$通过二分把它们分治进行处理 不妨先来考虑下一个简单易懂的$O(NlogS)$的排序…
先说下权值线段树的概念吧 权值平均树 就是指区间维护值为这个区间内点出现次数和的线段树 用这个加权线段树 解决第k大问题就很方便了 int query(int l,int r,int rt,int k)//找第k大的数 { if(l==r) return l; int m=(l+r)/2; if(k<=sum[rt<<1]) return query(lson,k);//看左儿子的sum是否大于k大于的话 说明第k大的树在左儿子(利用出现的次数进行比对---建树的时候 边界是递增的) e…
题意:给定一个数列,求一个区间的第K大数 模板题, 其中的newl, newr 有点不明白. #include <iostream> #include <algorithm> using namespace std; ; ][M], tree[][M], sorted[M]; void build(int level, int left, int right) { if (left == right) return; ; ; for (i=left; i<=right; i+…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2665 代码: //#include<bits/stdc++.h> #include<iostream> #include<cmath> #include<algorithm> #define fi first #define se second #define INF 0x3f3f3f3f #define fio ios::sync_with_stdio(fal…
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…
http://acm.hdu.edu.cn/showproblem.php?pid=4417 Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2315    Accepted Submission(s): 1127 Problem Description Mario is world-famous plumber…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 43315   Accepted: 14296 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
例题:http://poj.org/problem?id=2104 最近可能是念念不忘,必有回响吧,总是看到区间第k大的问题,第一次看到是在知乎上有人面试被弄懵了后来又多次在比赛中看到.以前大概是知道怎么解决但是没有实际操作过.直到昨天看到了POJ上的2104题,一个标准的区间第K大询问,然后好好总结了一下区间第K大的问题. 普通人要是没想过这个问题,突然被问到第一个反应肯定和知乎上面试的哥们儿一样,把区间里面的所有数拎出来,排序,找第K个,但是这样时间复杂度是很大的,如果m次询问,时间复杂度是…
poj-2104(区间第K大问题) #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; struct T { int ls; int rs; int sum; }; ; T tri[*N]; int a[N],sort_a[N]; int rt[N]; int cnt; int n,m; void update (…