Every year, the ACM/ICPC team will hold many contests, some of them are training while others are school contests.
In the year of 2017, there are nn contests to be held, and at the beginning of year, we plans the time of each contest.
However, as things are changing. Some other events might affect the time of contest and our team leader wants to know some interesting things about the time of some events.
The first line contains an integer nn. (0 < n \le 10^50<n≤105)
The second line contains nn integers, the ii-th one of them is t_iti, which is the planning time of contest ii at the beginning of this year. (0\le t_i \le 10^90≤ti≤109)
The third line contains an integer qq. And then qq lines follows. (0 < q \le 10^50<q≤105)
Then each line contains three integers. L_iLi, R_iRi, T_iTi, means the time of L_iLi-th contest to R_iRi-th contest will be changed by T_iTi. And then you should output the earlist time of L_iLi-th contest to R_iRi-th contest in the history after the change of time. (0 < L_i \le R_i \le n0<Li≤Ri≤n, |T_i| \le 10^9∣Ti∣≤109)
Output contains qq lines, ii-th line is the answer after ii-th query.
4
1 2 3 4
3
1 2 2
2 3 3
3 4 -10
1
2
-6
At the beginning, t_iti are (1,2,3,4)(1,2,3,4). After the first change on time, t_iti becomes (3,4,3,4)(3,4,3,4), and then (3,7,6,4)(3,7,6,4), and at last becomes (3,7,-4,-6)(3,7,−4,−6).
Be careful that as the times are relative times, so they can be negative.
题意:n场比赛,m次操作,每场比赛有个初值,操作每次把一个区间的比赛时间修改,每次修改完需要统计这个区间历史的时间最小值。
分析:线段树问题,区间修改和区间询问。
坑点:区间问题需要一个延迟标记 cur,如果多次对一个区间进行覆盖,延迟标记cur多次累加,而下面的节点没有随之进行更新就会出现无法更新到最小值。
比如这个测试数据:
8
0 0 0 0 0 0 0 0
4
1 2 -1
1 4 -1
1 4 1
2 2 0
最后的一组 答案是-2
处理:首先是变量,每个节点需要 有一个当前最小值m、一个历史最小值 lm,一个延迟标记累加和(和指的是延迟标记累加的得到的结果) cur,一个用来保存当cur多次累加时出现的最小和 mcur,一个延迟标记累加前的m值用 变量 sm 储存。当 rt 节点 pushdown时,需要更新 rt 节点 左右孩子节点lc和rc。更新lc节点的mcur时 ,mcur就等于min(cur(lc)+mcur(rt),mcur(lc)),然后 lm(lc) =min(mcur(lc)+sm(lc),lm(lc)),接着更新lc节点的cur和m,cur(lc)+=cur(rt),m(lc)+=cur(rt);
代码;
#include
#include
#include
#include
#include
#include
#include