CF280D.k-Maximum Subsequence Sum

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Consider integer sequence _a_1, _a_2, ..., a__n. You should run queries of two types:

  • The query format is "0 i val". In reply to this query you should make the following assignment: a__i = val.
  • The query format is "1 l r k". In reply to this query you should print the maximum sum of at most k non-intersecting subsegments of sequence a__l, a__l + 1, ..., a__r. Formally, you should choose at most k pairs of integers (_x_1, _y_1), (_x_2, _y_2), ..., (x__t, y__t) (l ≤ _x_1 ≤ _y_1 < _x_2 ≤ _y_2 < ... < x__t ≤ y__t ≤ r; t ≤ k) such that the sum _a__x_1 + _a__x_1 + 1 + ... + _a__y_1 + _a__x_2 + _a__x_2 + 1 + ... + _a__y_2 + ... + a__x__t + a__x__t + 1 + ... + a__y__t is as large as possible. Note that you should choose at most k subsegments. Particularly, you can choose 0 subsegments. In this case the described sum considered equal to zero.

考虑整数序列 a1,a2,…,ana_1, a_2, \dots, a_n。你需要处理两类查询:

  • 查询格式为 "0 i val"。对于该查询,你需要执行如下赋值操作:ai=vala_i = \text{val}。
  • 查询格式为 "1 l r k"。对于该查询,你需要输出序列 al,al+1,…,ara_l, a_{l+1}, \dots, a_r 中至多 kk 个互不相交子段的最大和。形式上,你需要选择至多 kk 对整数 (x1,y1),(x2,y2),…,(xt,yt)(x_1, y_1), (x_2, y_2), \dots, (x_t, y_t),满足

    l≤x1≤y1<x2≤y2<⋯<xt≤yt≤r,t≤k,l \le x_1 \le y_1 < x_2 \le y_2 < \dots < x_t \le y_t \le r,\quad t \le k,

    使得和

    ax1+ax1+1+⋯+ay1+ax2+ax2+1+⋯+ay2+⋯+axt+axt+1+⋯+ayta_{x_1} + a_{x_1+1} + \dots + a_{y_1} + a_{x_2} + a_{x_2+1} + \dots + a_{y_2} + \dots + a_{x_t} + a_{x_t+1} + \dots + a_{y_t}

    尽可能大。注意你最多只能选择 kk 个子段;特别地,你可以选择 00 个子段,此时上述和定义为 00。

输入格式

The first line contains integer n (1 ≤ n ≤ 105), showing how many numbers the sequence has. The next line contains n integers _a_1, _a_2, ..., a__n (|a__i| ≤ 500).

The third line contains integer m (1 ≤ m ≤ 105) — the number of queries. The next m lines contain the queries in the format, given in the statement.

All changing queries fit into limits: 1 ≤ i ≤ n, |val| ≤ 500.

All queries to count the maximum sum of at most k non-intersecting subsegments fit into limits: 1 ≤ l ≤ r ≤ n, 1 ≤ k ≤ 20. It is guaranteed that the number of the queries to count the maximum sum of at most k non-intersecting subsegments doesn't exceed 10000.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示序列中数字的个数。第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(∣ai∣≤500|a_i| \leq 500)。

第三行包含一个整数 mm(1≤m≤1051 \leq m \leq 10^5),表示查询的个数。接下来的 mm 行包含题目描述中所给格式的查询。

所有修改类查询均满足如下限制:1≤i≤n1 \leq i \leq n,∣val∣≤500|val| \leq 500。

所有计算区间 [l,r][l, r] 内至多 kk 个互不相交子区间的最大和的查询均满足如下限制:1≤l≤r≤n1 \leq l \leq r \leq n,1≤k≤201 \leq k \leq 20。保证此类查询的总数不超过 1000010000。

输出格式

For each query to count the maximum sum of at most k non-intersecting subsegments print the reply — the maximum sum. Print the answers to the queries in the order, in which the queries follow in the input.

对于每个查询(计算最多 k 个互不相交子区间的最大和),输出对应的答案——该最大和。请按照输入中查询出现的顺序输出各查询的答案。

输入输出样例

  • 输入#1

    9
    9 -8 9 -1 -1 -1 9 -8 9
    3
    1 1 9 1
    1 1 9 2
    1 4 6 3

    输出#1

    17
    25
    0
  • 输入#2

    15
    -4 8 -3 -10 10 4 -7 -7 0 -6 3 8 -10 7 2
    15
    1 3 9 2
    1 6 12 1
    0 6 5
    0 10 -7
    1 4 9 1
    1 7 9 1
    0 10 -3
    1 4 10 2
    1 3 13 2
    1 4 11 2
    0 15 -9
    0 13 -9
    0 11 -10
    1 5 14 2
    1 6 12 1

    输出#2

    14
    11
    15
    0
    15
    26
    18
    23
    8

说明/提示

In the first query of the first example you can select a single pair (1, 9). So the described sum will be 17.

Look at the second query of the first example. How to choose two subsegments? (1, 3) and (7, 9)? Definitely not, the sum we could get from (1, 3) and (7, 9) is 20, against the optimal configuration (1, 7) and (9, 9) with 25.

The answer to the third query is 0, we prefer select nothing if all of the numbers in the given interval are negative.

在第一个例子的第一个查询中,你可以选择唯一一对子段 (1, 9)(1,\ 9)。因此,所描述的和为 1717。

观察第一个例子的第二个查询:如何选择两个子段?(1, 3)(1,\ 3) 和 (7, 9)(7,\ 9)?显然不行,从 (1, 3)(1,\ 3) 和 (7, 9)(7,\ 9) 得到的和为 2020,而最优配置 (1, 7)(1,\ 7) 和 (9, 9)(9,\ 9) 对应的和为 2525。

第三个查询的答案是 00:如果给定区间内的所有数均为负数,我们宁愿不选任何子段。

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

首页