K-th Number Poj - 2104 主席树】的更多相关文章

K-th Number Poj - 2104 主席树 题意 给你n数字,然后有m次询问,询问一段区间内的第k小的数. 解题思路 这个题是限时训练做的题,我不会,看到这个题我开始是拒绝的,虽然题意清晰简单,但是真的不会.限时结束后,学长说这个题是简单的主席树的入门题,我没学过啊. 如果你也没有学过的话,建议看我的另一篇博客,上面有自己的总结和一些博客推荐,就不用自己一个一个找了,点我进去. 哦, 这个题是主席树的模板题. 代码实现 #include<cstdio> #include<cst…
题目链接:http://poj.org/problem?id=2104 主席树入门题目,主席树其实就是可持久化权值线段树,rt[i]维护了前i个数中第i大(小)的数出现次数的信息,通过查询两棵树的差即可得到第k大(小)元素. #include<cstdio> #include<vector> #include<algorithm> using namespace std; #define lson(i) node[i].lson #define rson(i) node…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 44940   Accepted: 14946 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 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…
传送门 题目大意应该都清楚. 今天看到一篇博客用分块+莫对做了这道题,直接惊呆了. 首先常规地离散化后将询问分块,对于某一询问,将莫队指针移动到指定区间,移动的同时处理权值分块的数字出现次数(单独.整块),莫队完后,现在的权值分块就是关于当前区间的.然后再从左到右扫描分块,直到数字个数+该块个数>=k,这时进入该块逐个加,当数字个数>=k时,直接跳出输出离散化之前的数字. 试了很多种块的大小,最后还是选择sqrt(100000) ≈ 320,时间比我的主席树还少(肯定是我写的丑). code…
#include <iostream> #include <cstdio> #include <algorithm> int const maxn = 200010; using namespace std; int a[maxn], b[maxn]; //第几个版本的根节点编号 int root[maxn << 5]; int lc[maxn << 5], rc[maxn << 5], sum[maxn << 5]; i…
一.主席树与权值线段树区别 主席树是由许多权值线段树构成,单独的权值线段树只能解决寻找整个区间第k大/小值问题(什么叫整个区间,比如你对区间[1,8]建立一颗对应权值线段树,那么你不能询问区间[2,5]第k大/小值,你只能询问[1,8]第k大/小值问题) 二.权值线段树是什么鬼 学权值线段树之前你肯定要知道线段树,线段树是对区间中的所有数进行维护 权值线段树维护的对象和它不同,权值<==>这个数在这个区间中出现的次数 例如1.5.3.2.4 建立的权值线段树: 你会发现,权值线段树的建立和线段…
K-th Number POJ - 2104 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 i…
BZOJ_4026_dC Loves Number Theory _主席树+欧拉函数 Description  dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯 竭的水题资源.    给定一个长度为 n的正整数序列A,有q次询问,每次询问一段区间内所有元素乘积的 φ(φ(n)代表1~n 中与n互质的数的个数) .由于答案可能很大,所以请对答案 mod 10^6 +  777. (本题强制在线,所有询问操作的l,r都需要 xor上一次询问的答案 lastans,…
Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16941    Accepted Submission(s): 5190 Problem Description Give you a sequence and ask you the kth big number of a inteval.   Input The…