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 aa of length nn and an array kk of length n−1n-1 are given. Two types of queries should be processed:

  • increase aia_i by xx. Then if ai+1<ai+kia_{i+1} \lt a_i + k_i, ai+1a_{i+1} becomes exactly ai+kia_i + k_i; again, if ai+2<ai+1+ki+1a_{i+2} \lt a_{i+1} + k_{i+1}, ai+2a_{i+2} becomes exactly ai+1+ki+1a_{i+1} + k_{i+1}, and so far for ai+3a_{i+3}, ..., ana_n;
  • 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+1a_i + k_i \leq a_{i+1} for all 1≤i≤n−11 \leq i \leq n-1.

本题中,Nastya 要求我们写出一个形式化的题目描述。

给定一个长度为 nn 的数组 aa 和一个长度为 n−1n-1 的数组 kk。需处理两类查询:

  • 将 aia_i 增加 xx;随后,若 ai+1<ai+kia_{i+1} \lt a_i + k_i,则令 ai+1a_{i+1} 恰好等于 ai+kia_i + k_i;接着,若 ai+2<ai+1+ki+1a_{i+2} \lt a_{i+1} + k_{i+1},则令 ai+2a_{i+2} 恰好等于 ai+1+ki+1a_{i+1} + k_{i+1};依此类推,直至 ai+3,…,ana_{i+3},\dots,a_n;
  • 输出数组 aa 中从第 ll 个元素到第 rr 个元素(含端点)的连续子数组之和。

保证初始时对所有 1≤i≤n−11 \leq i \leq n-1,均有 ai+ki≤ai+1a_i + k_i \leq a_{i+1}。

输入格式

The first line contains a single integer nn (2≤n≤1052 \leq n \leq 10^{5}) — the number of elements in the array aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−109≤ai≤109-10^{9} \leq a_i \leq 10^{9}) — the elements of the array aa.

The third line contains n−1n-1 integers k1,k2,…,kn−1k_1, k_2, \ldots, k_{n-1} (−106≤ki≤106-10^{6} \leq k_i \leq 10^{6}) — the elements of the array kk.

The fourth line contains a single integer qq (1≤q≤1051 \leq q \leq 10^{5}) — 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 \leq i \leq n, 0≤x≤1060 \leq x \leq 10^{6}), 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 ll and rr (1≤l≤r≤n1 \leq l \leq r \leq n).

第一行包含一个整数 nn(2≤n≤1052 \leq n \leq 10^{5})—— 数组 aa 的元素个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−109≤ai≤109-10^{9} \leq a_i \leq 10^{9})—— 数组 aa 的元素。

第三行包含 n−1n-1 个整数 k1,k2,…,kn−1k_1, k_2, \ldots, k_{n-1}(−106≤ki≤106-10^{6} \leq k_i \leq 10^{6})—— 数组 kk 的元素。

第四行包含一个整数 qq(1≤q≤1051 \leq q \leq 10^{5})—— 查询的个数。

接下来的 qq 行中,每行包含以下两种类型之一的查询:

  • 若为第一类查询,则该行包含字符 '+'(不含引号),后跟两个整数 ii 和 xx(1≤i≤n1 \leq i \leq n,0≤x≤1060 \leq x \leq 10^{6}),表示按题面描述将整数 xx 加到数组 aa 的第 ii 个元素上;
  • 若为第二类查询,则该行包含字符 's'(不含引号),后跟两个整数 ll 和 rr(1≤l≤r≤n1 \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]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].

在第一个例子中:

  • 第一次修改后,a=[3,4,3]a = [3, 4, 3];
  • 第二次修改后,a=[3,4,4]a = [3, 4, 4]。

在第二个例子中:

  • 第一次修改后,a=[6,9,10]a = [6, 9, 10];
  • 第二次修改后,a=[6,13,14]a = [6, 13, 14]。

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

首页