于是我们可以有这样的思路:每个结点维护该区间的最大值maxx,次大值sec,区间和sum以及区间最大值的个数cnt 接下来考虑对t取min的操作: 如果maxx≤t那么此操作无意义,直接跳过 如果sec≤t<maxx,则这次操作只对最大值有效,那么区间和减去cnt×(maxx−t),最大值更新为t并打标记 如果sec>t那么这时你发现你不知...
实际上,对于当前区间nownow的最大值和子区间的关系,只会出现上述1,2两种情况。因为在没修改时,nownow的最大、次大值肯定分别大于等于子区间的最大、次大值;当修改的时候,只有满足条件2才会修改,因此次大值并没有改变,也就是说,仍满足nownow的次大值大于等于子区间的次大值,所以下传的时候只会出现条件1,2....
1.若修改值大于严格次大值,可以打上懒标记并维护上述信息 2.若修改值不超过严格次大值,继续递归下去 (另外,该信息显然也可以up维护) 考虑这样的修改复杂度,定义势能为线段树所有节点对应区间内元素种类数和,那么修改时的第2种情况,必然会导致该区间对势能贡献减小1,因此均摊复杂度为$o(\log n)$ 势能范围为$[...
Gorgeous Sequence There is a sequence a of length n. We use ai to denote the i-th element in this sequence. You should do the following three types of operations to this sequence. 0 x y t: For every x≤i≤y, we use min(ai,t) to replace the original ai's value. 1 x y: Pri...
Welfare State + hdu5306 Gorgeous Sequence (吉司机线段树)存个板子更新操作区间取最值,n(logn)2更新操作区间取最值,n(logn)2Codeforces Round #576 (Div. 2) D. Welfare State#include<bits/stdc++.h> using namespace std; #define ls rt<<
【HDU5306】Gorgeous Sequence 这个题目是Segment-Tree-beats的论文的第一题。 首先我们考虑下这个问题的不同之处在于,有一个区间对x取max的操作。 那么如何维护这个操作呢? 就是对于线段树的区间,维护一个最大值标记,最大值出现次数,以及严格次大值。
2xy2 x y: Print the sum ofaiai thatx≤i≤yx≤i≤y. InputThe first line of the input is a single integerTT, indicating the number of testcases. The first line contains two integersnn andmm denoting the length of the sequence and the number of operations. ...
HDU5306 Gorgeous Sequence (吉司机线段树) #include<iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<vector>#include<string>#include<cstring>#include#include<set>usingnamespacestd; typedeflonglongll;constintN=1e6+10;structnode{intl,r; ll cnt...
HDU 5306 Gorgeous Sequence(区间最值操作 吉司机线段树 简单模板题),现在有这样的一个问题:你有一个长度为$n(n\le1e6)$的序列,你将会进行$m(m\le1e6)$次操作,每次操作属于下列三种形式之一:\(0\l\r\x\),表示对于每一个$i(l\lei\ler)$,进行$a_i=min(a_i,x)$操作。\
【HDU5306】【DTOJ2481】Gorgeous Sequence【线段树】 题目大意:给你一个序列a,你有三个操作,0: x y t将a[x,y]和t取min;1:x y求a[x,y]的最大值;2:x y求a[x,y]的sum 题解:首先很明显就是线段树裸题,那么考虑如何维护 区间最大值和区间sum很好维护,0操作不好做,那么考虑怎么快速解决0操作...