CF1136E.Nastya Hasn't Written a Legend
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In this task, Nastya asked us to write a formal statement.
An array a of length n and an array k of length n−1 are given. Two types of queries should be processed:
- increase ai by x. Then if ai+1<ai+ki, ai+1 becomes exactly ai+ki; again, if ai+2<ai+1+ki+1, ai+2 becomes exactly ai+1+ki+1, and so far for ai+3, ..., an;
- print the sum of the contiguous subarray from the l-th element to the r-th element of the array a.
It's guaranteed that initially ai+ki≤ai+1 for all 1≤i≤n−1.
本题中,Nastya 要求我们写出一个形式化的题目描述。
给定一个长度为 n 的数组 a 和一个长度为 n−1 的数组 k。需处理两类查询:
- 将 ai 增加 x;随后,若 ai+1<ai+ki,则令 ai+1 恰好等于 ai+ki;接着,若 ai+2<ai+1+ki+1,则令 ai+2 恰好等于 ai+1+ki+1;依此类推,直至 ai+3,…,an;
- 输出数组 a 中从第 l 个元素到第 r 个元素(含端点)的连续子数组之和。
保证初始时对所有 1≤i≤n−1,均有 ai+ki≤ai+1。
输入格式
The first line contains a single integer n (2≤n≤105) — the number of elements in the array a.
The second line contains n integers a1,a2,…,an (−109≤ai≤109) — the elements of the array a.
The third line contains n−1 integers k1,k2,…,kn−1 (−106≤ki≤106) — the elements of the array k.
The fourth line contains a single integer q (1≤q≤105) — the number of queries.
Each of the following q lines contains a query of one of two types:
- if the query has the first type, the corresponding line contains the character '+' (without quotes), and then there are two integers i and x (1≤i≤n, 0≤x≤106), it means that integer x is added to the i-th element of the array a as described in the statement.
- if the query has the second type, the corresponding line contains the character 's' (without quotes) and then there are two integers l and r (1≤l≤r≤n).
第一行包含一个整数 n(2≤n≤105)—— 数组 a 的元素个数。
第二行包含 n 个整数 a1,a2,…,an(−109≤ai≤109)—— 数组 a 的元素。
第三行包含 n−1 个整数 k1,k2,…,kn−1(−106≤ki≤106)—— 数组 k 的元素。
第四行包含一个整数 q(1≤q≤105)—— 查询的个数。
接下来的 q 行中,每行包含以下两种类型之一的查询:
- 若为第一类查询,则该行包含字符 '+'(不含引号),后跟两个整数 i 和 x(1≤i≤n,0≤x≤106),表示按题面描述将整数 x 加到数组 a 的第 i 个元素上;
- 若为第二类查询,则该行包含字符 's'(不含引号),后跟两个整数 l 和 r(1≤l≤r≤n)。
输出格式
For each query of the second type print a single integer in a new line — the sum of the corresponding subarray.
对于每个第二类查询,在新的一行中输出一个整数——对应子数组的元素和。
输入输出样例
输入#1
3 1 2 3 1 -1 5 s 2 3 + 1 2 s 1 2 + 3 1 s 2 3
输出#1
5 7 8
输入#2
3 3 6 7 3 1 3 + 1 3 + 2 4 s 1 3
输出#2
33
说明/提示
In the first example:
- after the first change a=[3,4,3];
- after the second change a=[3,4,4].
In the second example:
- after the first change a=[6,9,10];
- after the second change a=[6,13,14].
在第一个例子中:
- 第一次修改后,a=[3,4,3];
- 第二次修改后,a=[3,4,4]。
在第二个例子中:
- 第一次修改后,a=[6,9,10];
- 第二次修改后,a=[6,13,14]。
输入解题思路,AI测评打分。不知道怎么写?