题意:https://codeforc.es/contest/1208/problem/D 给你长度为n的序列,s[i]的值为p[1]到p[i-1]中比p[i]小的数的和,让你求出p序列. 思路: 首先我们要想到,最后一个0的位置一定就是当前剩余还没用确定的数里的最小值,所以从1,2,3 ...一直下去就行了. 选过了就在线段树上改为INF,同时pushup维护的最右边为0的位置. 一开始单点修改忘记down下去了,改了好久,学到了学到了. #define IOS ios_base::sync_…
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组 [Problem Description] ​ 给你一个长度为\(n\)的数组,第\(i\)个元素\(s_i\)表示一个排列中第\(i\)个元素之前,并且小于\(p_i\)的元素的和.求出满足此条件的排列. [Solution] ​ 假设\(n=5\),\(s[]=\{0,0,3,7,3\}\).从后往前看…
//树状数组中数组的特性,有更巧妙的方法.//我们知道在树状数组中,对于数组tree[i],它所维护的区间为[i−lowbit(i)+1,i]//所以对于tree[2^i],它所维护的区间就为[1,2^i].//所以就可以利用此特性加上树状数组的操作,维护一个类似倍增方法,并且支持在线修改操作.#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long a[200007],tree[20000…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long ans[1000007];vector<pair<int,int> >add[1000007],remv[1000007];multiset<int>s[1000007];//也可以用deque,rmq等数据结构实现,多重集自带排序int main(){ int n,w; cin>>n&…
F - Permutation 思路:对于当前的值x, 只需要知道x + k, x - k这两个值是否出现在其左右两侧,又因为每个值只有一个, 所以可以转换成,x+k, x-k在到x所在位置的时候是否都出现,或者都不出现,即出现情况相等,我们可以 用线段树维护hash值的方式来判断所有x+k,  x-k的出现情况是否都一样. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #defi…
肯定先无脑树链剖分,然后线段树维护一段区间不同个数,再维护一个左右端点的费用. 线段树更新,pushDown,pushUp的时候要注意考虑链接位置的费用是否相同 还有就是树链剖分操作的时候,维护上一个更新的位置的费用. 总之就是出现区间合并,就考虑总数是否要减一 好想不好写 //场上根本写不完啊 /*--------------------------------------------------------------------------------------*/ #include <…
Another LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1244    Accepted Submission(s): 431 Problem Description There is a sequence firstly empty. We begin to add number from 1 to N to the s…
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是那题有简单方法,于是就没写.这次最终写出来了.. 这题的DP思想跟求最长上升子序列的思想是一样的.仅仅只是这里的找前面最大值时会超时,所以能够用线段树来维护这个最大值,然后因为还要输出路径,所以要用线段树再来维护一个每一个数在序列中所在的位置信息. 手残了好多地方,最终调试出来了... 代码例如以下…
D. The Bakery time limit per test:2.5 seconds memory limit per test:256 megabytes input:standard input output:standard output Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven whic…
[Codeforces]817F. MEX Queries You are given a set of integer numbers, initially it is empty. You should perform n queries. There are three different types of queries: 1 l r — Add all missing numbers from the interval [l, r] 2 l r — Remove all present…