CF1406D.Three Sequences

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a sequence of nn integers a1,a2,…,ana_1, a_2, \ldots, a_n.

You have to construct two sequences of integers bb and cc with length nn that satisfy:

  • for every ii (1≤i≤n1\leq i\leq n) bi+ci=aib_i+c_i=a_i
  • bb is non-decreasing, which means that for every 1<i≤n1 \lt i\leq n, bi≥bi−1b_i\geq b_{i-1} must hold
  • cc is non-increasing, which means that for every 1<i≤n1 \lt i\leq n, ci≤ci−1c_i\leq c_{i-1} must hold

You have to minimize max⁡(bi,ci)\max(b_i,c_i). In other words, you have to minimize the maximum number in sequences bb and cc.

Also there will be qq changes, the ii-th change is described by three integers l,r,xl,r,x. You should add xx to al,al+1,…,ara_l,a_{l+1}, \ldots, a_r.

You have to find the minimum possible value of max⁡(bi,ci)\max(b_i,c_i) for the initial sequence and for sequence after each change.

给定一个长度为 nn 的整数序列 a1,a2,…,ana_1, a_2, \ldots, a_n。

你需要构造两个长度为 nn 的整数序列 bb 和 cc,满足以下条件:

  • 对每个 ii(1≤i≤n1\leq i\leq n),有 bi+ci=aib_i+c_i=a_i;
  • bb 是非递减序列,即对每个 1<i≤n1 < i\leq n,均有 bi≥bi−1b_i\geq b_{i-1};
  • cc 是非递增序列,即对每个 1<i≤n1 < i\leq n,均有 ci≤ci−1c_i\leq c_{i-1}。

你需要最小化 max⁡(bi,ci)\max(b_i,c_i)。换言之,你要最小化序列 bb 和 cc 中所有元素的最大值。

此外,还会有 qq 次修改操作,第 ii 次修改由三个整数 l,r,xl,r,x 描述:你需要将 al,al+1,…,ara_l,a_{l+1}, \ldots, a_r 均增加 xx。

你需要分别求出初始序列,以及每次修改后的序列所对应的 max⁡(bi,ci)\max(b_i,c_i) 的最小可能值。

输入格式

The first line contains an integer nn (1≤n≤1051\leq n\leq 10^5).

The secound line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤i≤n1\leq i\leq n, −109≤ai≤109-10^9\leq a_i\leq 10^9).

The third line contains an integer qq (1≤q≤1051\leq q\leq 10^5).

Each of the next qq lines contains three integers l,r,xl,r,x (1≤l≤r≤n,−109≤x≤1091\leq l\leq r\leq n,-10^9\leq x\leq 10^9), desribing the next change.

第一行包含一个整数 nn(1≤n≤1051\leq n\leq 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤i≤n1\leq i\leq n,−109≤ai≤109-10^9\leq a_i\leq 10^9)。

第三行包含一个整数 qq(1≤q≤1051\leq q\leq 10^5)。

接下来的 qq 行中,每行包含三个整数 l,r,xl,r,x(1≤l≤r≤n1\leq l\leq r\leq n,−109≤x≤109-10^9\leq x\leq 10^9),描述一次更新操作。

输出格式

Print q+1q+1 lines.

On the ii-th (1≤i≤q+11 \leq i \leq q+1) line, print the answer to the problem for the sequence after i−1i-1 changes.

输出 q+1q+1 行。

在第 ii 行(1≤i≤q+11 \leq i \leq q+1),输出经过 i−1i-1 次修改后的序列对应问题的答案。

输入输出样例

  • 输入#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)a = (2, -1, 7, 3). Two sequences b=(−3,−3,5,5),c=(5,2,2,−2)b=(-3,-3,5,5),c=(5,2,2,-2) is a possible choice.
  • After the first change a=(2,−4,4,0)a = (2, -4, 4, 0). Two sequences b=(−3,−3,5,5),c=(5,−1,−1,−5)b=(-3,-3,5,5),c=(5,-1,-1,-5) is a possible choice.
  • After the second change a=(2,−4,6,2)a = (2, -4, 6, 2). Two sequences b=(−4,−4,6,6),c=(6,0,0,−4)b=(-4,-4,6,6),c=(6,0,0,-4) is a possible choice.

在第一个测试用例中:

  • 初始序列 a=(2,−1,7,3)a = (2, -1, 7, 3)。序列 b=(−3,−3,5,5)b=(-3,-3,5,5) 和 c=(5,2,2,−2)c=(5,2,2,-2) 是一种可行的选择。
  • 第一次变换后,a=(2,−4,4,0)a = (2, -4, 4, 0)。序列 b=(−3,−3,5,5)b=(-3,-3,5,5) 和 c=(5,−1,−1,−5)c=(5,-1,-1,-5) 是一种可行的选择。
  • 第二次变换后,a=(2,−4,6,2)a = (2, -4, 6, 2)。序列 b=(−4,−4,6,6)b=(-4,-4,6,6) 和 c=(6,0,0,−4)c=(6,0,0,-4) 是一种可行的选择。

输入解题思路,AI测评打分。不知道怎么写?

首页