POJ 2104 区间第k大(主席树)】的更多相关文章

题目链接:http://poj.org/problem?id=2104 题目大意:给定还有n个数的序列,m个操作,每个操作含有l,r,k,求区间[l,r]第k大 解题思路:线段树只能维护序列的最大值最小值,考虑对于输入的序列的每一个前缀建立一颗线段树,即含有n颗线段树,这样肯定会爆内存.相邻两颗线段树其实有很多相同的,不同的大概就是 log n个节点,我们新开log n个节点就可以了.每个节点存的sum值为当前节点数字出现的次数,对于区间[l,r],我们可以用第r颗线段树减去第l-1颗线段树得到…
题目链接 K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 36890 Accepted: 11860 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key ins…
题目链接 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…
Distance on the tree DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(National Olympiad in Informatics in Provinces) in Senior High School. So when in Data Structure Class in College, he is always absent-minded about…
http://poj.org/problem?id=2104 裸题不说.主席树水过. #include <cstdio> #include <iostream> #include <algorithm> using namespace std; #define dbg(x) cout << #x << "=" << x << endl #define read(x) x=getint() #define…
题目链接:https://www.spoj.com/problems/COT/en/ 题目: 题意: 给你一棵有n个节点的树,求节点u到节点v这条链上的第k大. 思路: 我们首先用dfs进行建题目给的树,然后在dfs时进行主席树的update操作.众所周知,主席树采用的是前缀和思想,区间第k大是与前一个树添加新的线段树,而树上第k大则是与父亲节点添加新的线段树,因而在此思想上此题的答案为sum[u] + sum[v] - sum[lca(u,v)] - sum[fa[lca(u,v)].求第k大…
题目大意:对于一个序列,每次询问区间[l,r]的第k大树. 分析: 主席树模板题 program kthtree; type point=record l,r,s:longint; end; var t:..*]of point; a,b,id,root:..]of longint; n,i,m,x,y,k,v,len:longint; procedure qsort(l,h:longint); var i,j,t,m:longint; begin i:=l; j:=h; m:=a[(i+j)…
给定一个n的序列,有m个询问 每次询问求l-r 里面第k大的数字是什么 只有询问,没有修改 可以用归并树和划分树(我都没学过..囧) 我是专门冲着弄主席树来的 对主席树的建树方式有点了解了,不过这题为什么是在主席树里面这么操作的 还是有点不懂,今天照着模板敲了一遍就打多校了 再研究吧 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using name…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 31790   Accepted: 9838 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inser…