CF1406D.Three Sequences
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a sequence of n integers a1,a2,…,an .
You have to construct two sequences of integers b and c with length n that satisfy:
- for every i ( 1≤i≤n ) bi+ci=ai
- b is non-decreasing, which means that for every 1<i≤n , bi≥bi−1 must hold
- c is non-increasing, which means that for every 1<i≤n , ci≤ci−1 must hold
You have to minimize max(bi,ci) . In other words, you have to minimize the maximum number in sequences b and c .
Also there will be q changes, the i -th change is described by three integers l,r,x . You should add x to al,al+1,…,ar .
You have to find the minimum possible value of max(bi,ci) for the initial sequence and for sequence after each change.
输入格式
The first line contains an integer n ( 1≤n≤105 ).
The secound line contains n integers a1,a2,…,an ( 1≤i≤n , −109≤ai≤109 ).
The third line contains an integer q ( 1≤q≤105 ).
Each of the next q lines contains three integers l,r,x ( 1≤l≤r≤n,−109≤x≤109 ), desribing the next change.
输出格式
Print q+1 lines.
On the i -th ( 1≤i≤q+1 ) line, print the answer to the problem for the sequence after i−1 changes.
输入输出样例
输入#1
4 2 -1 7 3 2 2 4 -3 3 4 2
输出#1
5 5 6
输入#2
6 -9 -10 -9 -6 -5 4 3 2 6 -9 1 2 -10 4 6 -3
输出#2
3 3 3 1
输入#3
1 0 2 1 1 -1 1 1 -1
输出#3
0 0 -1
说明/提示
In the first test:
- The initial sequence a=(2,−1,7,3) . Two sequences b=(−3,−3,5,5),c=(5,2,2,−2) is a possible choice.
- After the first change a=(2,−4,4,0) . Two sequences b=(−3,−3,5,5),c=(5,−1,−1,−5) is a possible choice.
- After the second change a=(2,−4,6,2) . Two sequences b=(−4,−4,6,6),c=(6,0,0,−4) is a possible choice.