hdu-5306(区间最值+线段树) hduGorgeous SequenceHDU - 5306 题意:给定一个长度为n的区间,做m次操作,三种操作对于序列[L,R]区间中的每个ai,用min(ai,x)替换。 打印序列[L,R]区间的最大值 打印序列[L,R]区间和因为区间和与区间最值无关,所以无法直接用简单的标记处理。
}returna*b; }constintN = 1e6 +5;inta[N], mx[N<<2], cnt[N<<2], se[N<<2], lazy[N<<2], n, m, op, x, y, t, T; LL sum[N<<2]; inlinevoidpush_up(intrt) { sum[rt]= sum[rt<<1] + sum[rt<<1|1]; mx[rt]= max(mx[rt<<1], mx[rt<<1|1]);if(mx[rt<...
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. The second line containsnn se...
二、解题思路 对于这样的问题(包括其各种加强版),\(jls\)在\(2016\)的国家集训队论文集中给出了如下的解法,即\(segment\) \(tree\) \(beats\),一种采用势能思想的线段树。 吉老师论文: 三、实现代码 #include <iostream> using namespace std; typedef long long LL; const int INF = 0x3f3f3f3f; ...
HDU - 5306 Gorgeous Sequence 题意: 给定一个长为 n 的数组 a,有 m 个操作,①:0,x,y,t,令 ai=min(ai,t),i∈[x,y]a_i = min(a_i, t),i∈[x, y]ai=min(ai,t),i∈[x,y];②:1,x,y,询问 max{ ax,ax+1,...,aya_x, a_{x+1}, ..., a_yax,ax+1,....
0 x y t: For every x≤i≤y, we use min(ai,t) to replace the original ai’s value.(区间取 min) 1 x y: Print the maximum value of ai that x≤i≤y.(区间求最大値) 2 x y: Print the sum of ai that x≤i≤y.(区间求和) ...
HDU - 5306 Gorgeous Sequence 线段树 + 均摊分析 Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 ...
传送门 [l,r] 区间,把大于x的变成x 求区间最大值 求区间和 普通线段树不能做到区间取min操作,但是吉老师提出了一个方法传送门 在普通线段树基础上,每个结点维护的值有sum表示区间和,mx表示区间最大值,cnt表示区间最大值出现的次数,se表示区间次大值 其核心想法在于 当
hdu 5306 优先队列 #include 1#include<iostream>2#include<string>3#include<algorithm>4#include<cstdio>5#include<vector>6#include<queue>7#defineN 10000058usingnamespacestd;9structNode10{11intr,l,id;12booloperator<(Node a)const{returnl>a.l;}//为了优先队列的优先级的排列,>队列顶端是最小的,...
HDU5306 Gorgeous Sequence (jls线段树) HDU5306 Gorgeous Sequence (jls线段树) 3个操作: 1.区间最值修改。 2.区间求最值。 3.区间求和。 思路:开一个变量m x , s e mx,semx,se维护区间最大值和严格次大值,再开一个c n t cntcnt,维护区间最大值的个数。