A12378 | Nastya Hasn't Written a Legend
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $a_i$ by $x$ . Then if $a_{i+1} < a_i + k_i$ , $a_{i+1}$ becomes exactly $a_i + k_i$ ; again, if $a_{i+2} < a_{i+1} + k_{i+1}$ , $a_{i+2}$ becomes exactly $a_{i+1} + k_{i+1}$ , and so far for $a_{i+3}$ , ..., $a_n$ ;
- 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 $a_i + k_i \leq a_{i+1}$ for all $1 \leq i \leq n-1$ .
An array $a$ of length $n$ and an array $k$ of length $n-1$ are given. Two types of queries should be processed:
- increase $a_i$ by $x$ . Then if $a_{i+1} < a_i + k_i$ , $a_{i+1}$ becomes exactly $a_i + k_i$ ; again, if $a_{i+2} < a_{i+1} + k_{i+1}$ , $a_{i+2}$ becomes exactly $a_{i+1} + k_{i+1}$ , and so far for $a_{i+3}$ , ..., $a_n$ ;
- 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 $a_i + k_i \leq a_{i+1}$ for all $1 \leq i \leq n-1$ .
输入格式
The first line contains a single integer $n$ ( $2 \leq n \leq 10^{5}$ ) — the number of elements in the array $a$ .
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $-10^{9} \leq a_i \leq 10^{9}$ ) — the elements of the array $a$ .
The third line contains $n-1$ integers $k_1, k_2, \ldots, k_{n-1}$ ( $-10^{6} \leq k_i \leq 10^{6}$ ) — the elements of the array $k$ .
The fourth line contains a single integer $q$ ( $1 \leq q \leq 10^{5}$ ) — 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 \leq i \leq n$ , $0 \leq x \leq 10^{6}$ ), 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 \leq l \leq r \leq n$ ).
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $-10^{9} \leq a_i \leq 10^{9}$ ) — the elements of the array $a$ .
The third line contains $n-1$ integers $k_1, k_2, \ldots, k_{n-1}$ ( $-10^{6} \leq k_i \leq 10^{6}$ ) — the elements of the array $k$ .
The fourth line contains a single integer $q$ ( $1 \leq q \leq 10^{5}$ ) — 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 \leq i \leq n$ , $0 \leq x \leq 10^{6}$ ), 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 \leq l \leq r \leq 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]$ .
- 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]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted