Optimal Subsequences(主席树)】的更多相关文章

题意: 给定一个序列,长度为n(<=2e5),有m(<=2e5)个询问,每个询问包含k和pos,要从原序列中选出一个长度为k的子序列,要求是这个序列的和是所有长度为k的序列中最大的,且是字典序最小的,要求输出子序列中第pos个元素. 思路: 显然要是长度为k的序列中和最大,必须要优先选大的数.显然必须全部选的数不需要考虑位置,部分选的数(必定是最小的数)肯定优先选择坐标小的,因此可以将所有数按数值从大到小排,然后坐标从小到达排,前k的数就是每次要选的数.而第pos个元素就是排好的数前k个中坐标…
题意 给定长度为\(n\)的序列\(a\),以及m个询问\(<k,pos>\),每次询问满足下列条件的子序列中第\(pos\)位的值为多少. 子序列长度为\(k\) 序列和是所有长度为\(k\)的子序列中最大的 字典序是所有满足上述两个条件的序列中最小的 解题思路 稍作分析即可得出,将序列按值的大小作为第一关键字(升序),下标作为第二关键字(降序)排序,所得序列的后\(k\)个元素即为询问长度为\(k\)时满足给定条件的序列中的元素,所以答案就是后\(k\)个元素中下标第\(pos\)小的元素…
题目链接:https://codeforces.com/contest/1262/problem/D2 将数组按大到小排序(相同大小的按下标由小到大排序),依次将排序后的每个数在原数组中的位置放入主席树. 对于每个询问的k,pos 输出原数组中下标为query(T[0],T[k],1,len,pos)所对应的数字即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace std;…
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018. Input First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10…
D Optimal Subsequences http://codeforces.com/contest/1227/problem/D2 显然,每次求的k一定是这个序列从大到小排序后前k大的元素. 考虑如何做才能使其字典序最小.我们设p为第k大的元素. 首先,这k个数是确定的. 其次,对于比p大的所有元素,他们是必须选的. 所以,欲使这个序列字典序最小,其实就是让所有p出现的位置 尽量靠前. 那做法就很显然了:先离散化,搞出来一个相对排名,用主席树 维护相对排名.每次查询,二分答案,check就…
E. Sign on Fence   Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter width and of arbitrary height. The i-th panel's height is hi meters. The adjacent planks follow without a gap…
You are given a directed graph with n nodes and m edges, with all edges having a certain weight. There might be multiple edges and self loops, and the graph can also be disconnected. You need to choose a path (possibly passing through same vertices m…
D2. Optimal Subsequences (Hard Version) This is the harder version of the problem. In this version, 1≤n,m≤2⋅105. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a seque…
题目大意: 给定一个n个数的序列和m个询问(n,m<=100000)和k,每个询问包含k+2个数字:l,r,b[1],b[2]...b[k],要求输出b[1]~b[k]在[l,r]中是否出现. 思路:把所有连续的k个数字hash一下,然后扔进主席树,询问时在主席树中查询就可以了. 注意(坑)点:1.hash值要用unsigned long long存 2.如果直接求l+r>>1会爆,所以要改成(l>>1)+(r>>1)+(l&r&1) 3.Yes和…
树状数组套主席树模板题... 题目大意: 给定一个含有n个数的序列a[1],a[2],a[3]--a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]--a[j]中第k小的数是多少(1≤k≤j-i+1),并且,你可以改变一些a[i]的值,改变后,程序还能针对改变后的a继续回答上面的问题.你需要编一个这样的程序,从输入文件中读入序列a,然后读入一系列的指令,包括询问指令和修改指令.对于每一个询问指令,你必须输出正确的回答. 第一行有两个正整数n(1≤n≤1…