算法总结——主席树(poj2104)】的更多相关文章

题目: 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 a…
题意:给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…
[题目]F. Pathwalks [题意]给定n个点m条边的有向图,可能不连通有重边有自环.每条边有编号 i 和边权 wi ,求最长的路径(可以经过重复节点)满足编号和边权都严格递增.n,m,wi<=10^5. [算法]主席树+DP [题解]这个和LIS十分类似,只要在考虑LIS的树状数组做法的前提下多考虑节点搭配问题,即f[i]=f[j]+1还需要e[j].v=e[i].u. 所以对每个节点建可持久化线段树,然后DP即可.(当然也可以用可持久化树状数组) 复杂度O(n log n). #inc…
Super Mario  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 (the len…
主席树是可持久化线段树,可以记录线段树的历史版本. 代码中和线段树不同的是,l,r记录的是左右子树编号,因为普通的线段树版本中,左右子树自然就是o<<1和o<<1|1,但是主席树中并不保证这个特性,所以需要记录一下. 代码是 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> usin…
[POJ2104][HDU2665]K-th Number 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…
DQUERY - D-query Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). For each d-query (i, j), you have to return the number of distinct elements in the subsequence ai, ai+1, ..., aj. In…
题意:有n个数组成的序列,要求维护数据结构支持在线的下列两种操作: 1:单点修改,将第x个数修改成y 2:区间查询,询问从第x个数到第y个之间第K大的数 n<=100000,a[i]<=10^9 思路:一年前写过的第一道主席树,现在有了更深的理解 最朴素的想法是设t[i,j]为i时刻[1..j]的个数之和 询问时区间(x,y)时只需取出t[y]-t[x-1]这棵线段树,在其中二分查找即可 那么问题来了:这样的写法空间复杂度是O(n2)级别的,且每次更改只有logn个点会被更改 有很多一模一样的…
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…
题目链接  HH的项链 这道题可以直接上主席树的模板 #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define dec(i, a, b) for (int i(a); i >= (b); --i) typedef long long LL; const int N = 5e4 + 10; const int M = 3e6 + 10…