CF1609G.A Stroll Around the Matrix

NOI/NOI+/CTSC

通过率:0%

时间限制:6.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

William has two arrays of numbers a1,a2,…,ana_1, a_2, \dots, a_n and b1,b2,…,bmb_1, b_2, \dots, b_m. The arrays satisfy the conditions of being convex. Formally an array cc of length kk is considered convex if ci−ci−1<ci+1−cic_i - c_{i - 1} \lt c_{i + 1} - c_i for all ii from 22 to k−1k - 1 and c1<c2c_1 \lt c_2.

Throughout William's life he observed qq changes of two types happening to the arrays:

  1. Add the arithmetic progression d,d⋅2,d⋅3,…,d⋅kd, d \cdot 2, d \cdot 3, \dots, d \cdot k to the suffix of the array aa of length kk. The array after the change looks like this: [a1,a2,…,an−k,an−k+1+d,an−k+2+d⋅2,…,an+d⋅k][a_1, a_2, \dots, a_{n - k}, a_{n - k + 1} + d, a_{n - k + 2} + d \cdot 2, \dots, a_n + d \cdot k].
  2. The same operation, but for array bb.

After each change a matrix dd is created from arrays aa and bb, of size n×mn \times m, where di,j=ai+bjd_{i, j}=a_i + b_j. William wants to get from cell (1,11, 1) to cell (n,mn, m) of this matrix. From cell (x,yx, y) he can only move to cells (x+1,yx + 1, y) and (x,y+1x, y + 1). The length of a path is calculated as the sum of numbers in cells visited by William, including the first and the last cells.

After each change William wants you to help find out the minimal length of the path he could take.

威廉拥有两个数字数组 a1,a2,…,ana_1, a_2, \dots, a_n 和 b1,b2,…,bmb_1, b_2, \dots, b_m。这两个数组均满足凸性条件。形式化地,一个长度为 kk 的数组 cc 被称为凸数组,当且仅当对所有 ii 满足 2≤i≤k−12 \le i \le k-1,有 ci−ci−1<ci+1−cic_i - c_{i - 1} < c_{i + 1} - c_i,且 c1<c2c_1 < c_2。

在威廉的一生中,他观察到共 qq 次对这两个数组的修改,每次修改属于以下两种类型之一:

  1. 向数组 aa 的长度为 kk 的后缀添加等差数列 d, d⋅2, d⋅3, …, d⋅kd,\, d \cdot 2,\, d \cdot 3,\, \dots,\, d \cdot k。修改后的数组形如:
    [a1,a2,…,an−k,  an−k+1+d,  an−k+2+d⋅2,  …,  an+d⋅k][a_1, a_2, \dots, a_{n - k},\; a_{n - k + 1} + d,\; a_{n - k + 2} + d \cdot 2,\; \dots,\; a_n + d \cdot k]。
  2. 对数组 bb 执行完全相同的上述操作。

每次修改后,由数组 aa 和 bb 构造一个大小为 n×mn \times m 的矩阵 dd,其中元素定义为 di,j=ai+bjd_{i, j} = a_i + b_j。威廉希望从该矩阵的单元格 (1,1)(1, 1) 出发,到达单元格 (n,m)(n, m)。从单元格 (x,y)(x, y) 出发时,他只能移动至 (x+1,y)(x + 1, y) 或 (x,y+1)(x, y + 1)。一条路径的长度定义为威廉所经过的所有单元格(包括起点和终点)中数值之和。

每次修改后,威廉希望你帮他求出他所能选择的路径的最小可能长度。

输入格式

The first line contains three integers nn, mm and qq (2≤n≤100,2≤m≤1052 \le n \le 100, 2 \le m \le 10^5, 1≤q≤1051 \le q \le 10^5), the sizes of the arrays and the number of changes.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤10121 \le a_i \le 10^{12}), the contents of array aa.

The third line contains mm integers b1,b2,…,bmb_1, b_2, \dots, b_m (1≤bi≤10121 \le b_i \le 10^{12}), the contents of array bb.

Each of the next qq lines contains three integers typetype, kk and dd (1≤type≤21 \le type \le 2, if type=1type = 1, then 1≤k≤n1 \le k \le n otherwise 1≤k≤m1 \le k \le m, 1≤d≤1031 \le d \le 10^3).

第一行包含三个整数 nn、mm 和 qq(2≤n≤1002 \le n \le 100,2≤m≤1052 \le m \le 10^5,1≤q≤1051 \le q \le 10^5),分别表示数组的大小以及修改操作的次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤10121 \le a_i \le 10^{12}),表示数组 aa 的内容。

第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \dots, b_m(1≤bi≤10121 \le b_i \le 10^{12}),表示数组 bb 的内容。

接下来的 qq 行中,每行包含三个整数 typetype、kk 和 dd(1≤type≤21 \le type \le 2;若 type=1type = 1,则 1≤k≤n1 \le k \le n,否则 1≤k≤m1 \le k \le m;且 1≤d≤1031 \le d \le 10^3)。

输出格式

After each change, output one integer, the minimum length of the path in the constructed matrix.

每次修改后,输出一个整数,即所构造矩阵中路径的最短长度。

输入输出样例

  • 输入#1

    5 3 4
    1 2 4 7 11
    5 7 10
    1 3 2
    2 2 5
    1 5 4
    2 1 7

    输出#1

    98
    128
    219
    229
  • 输入#2

    5 6 7
    4 9 22 118 226
    7 94 238 395 565 738
    2 1 95
    1 4 54
    1 2 5
    1 2 87
    2 6 62
    2 1 143
    1 1 77

    输出#2

    3639
    5122
    5162
    5617
    7663
    7806
    7960

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

首页