传送门
题目:
In this task, Nastya asked us to write a formal statement.
An array aa of length nn and an array kk of length n−1n−1 are given. Two types of queries should be processed:
- increase aiai by xx. Then if ai+1
- print the sum of the contiguous subarray from the ll-th element to the rr-th element of the array aa.
It's guaranteed that initially ai+ki≤ai+1ai+ki≤ai+1 for all 1≤i≤n−11≤i≤n−1.
Input
The first line contains a single integer nn (2≤n≤1052≤n≤105) — the number of elements in the array aa.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109) — the elements of the array aa.
The third line contains n−1n−1 integers k1,k2,…,kn−1k1,k2,…,kn−1 (−106≤ki≤106−106≤ki≤106) — the elements of the array kk.
The fourth line contains a single integer qq (1≤q≤1051≤q≤105) — the number of queries.
Each of the following qq 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 ii and xx(1≤i≤n1≤i≤n, 0≤x≤1060≤x≤106), it means that integer xx is added to the ii-th element of the array aa 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 lland rr (1≤l≤r≤n1≤l≤r≤n).
Output
For each query of the second type print a single integer in a new line — the sum of the corresponding subarray.
Examples
input
Copy
3
1 2 3
1 -1
5
s 2 3
+ 1 2
s 1 2
+ 3 1
s 2 3
output
Copy
5
7
8
input
Copy
3
3 6 7
3 1
3
+ 1 3
+ 2 4
s 1 3
output
Copy
33
Note
In the first example:
- after the first change a=[3,4,3]a=[3,4,3];
- after the second change a=[3,4,4]a=[3,4,4].
In the second example:
- after the first change a=[6,9,10]a=[6,9,10];
after the second change a=[6,13,14]a=[6,13,14];
题意:给你俩个数组-x和k数组,x数组初始满足x[i]+k[i]<=x[i+1],m次操作,每次操作有俩种,一种是在x数组中的第i个加上一个值y;另一种就是输出i到y区间的x数组的合,对于x数组如果满足x[i]+k[i]>x[i+1],x[i+1]就会被替换为x[i]+k[i];
题解:定义y数组为k的前n项和,sum数组为y数组的前n项和,对于每次修改当x[i]+k[i]>x[i+1],x[i+1]就会被替换为x[i]+k[i];则以i为左端点在到最右边满足条件的右端点,这一区间都需要被修改,然后对于每次查询的区间合都可以用线段树实现,那么现在的问题就是如何确定右边界?
则只需要二分查找右端点就可以了,最后用线段数维护;
AC代码:
#include
#include
#include
#include
#include
#include
#include