CF1609G.A Stroll Around the Matrix
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
William has two arrays of numbers a1,a2,…,an and b1,b2,…,bm . The arrays satisfy the conditions of being convex. Formally an array c of length k is considered convex if ci−ci−1<ci+1−ci for all i from 2 to k−1 and c1<c2 .
Throughout William's life he observed q changes of two types happening to the arrays:
- Add the arithmetic progression d,d⋅2,d⋅3,…,d⋅k to the suffix of the array a of length k . The array after the change looks like this: [a1,a2,…,an−k,an−k+1+d,an−k+2+d⋅2,…,an+d⋅k] .
- The same operation, but for array b .
After each change a matrix d is created from arrays a and b , of size n×m , where di,j=ai+bj . William wants to get from cell ( 1,1 ) to cell ( n,m ) of this matrix. From cell ( x,y ) he can only move to cells ( x+1,y ) and ( x,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.
输入格式
The first line contains three integers n , m and q ( 2≤n≤100,2≤m≤105 , 1≤q≤105 ), the sizes of the arrays and the number of changes.
The second line contains n integers a1,a2,…,an ( 1≤ai≤1012 ), the contents of array a .
The third line contains m integers b1,b2,…,bm ( 1≤bi≤1012 ), the contents of array b .
Each of the next q lines contains three integers type , k and d ( 1≤type≤2 , if type=1 , then 1≤k≤n otherwise 1≤k≤m , 1≤d≤103 ).
输出格式
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