CF371D.Vessels

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a system of n vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to n, in the order from the highest to the lowest, the volume of the i-th vessel is a__i liters.

Initially, all the vessels are empty. In some vessels water is poured. All the water that overflows from the i-th vessel goes to the (i + 1)-th one. The liquid that overflows from the n-th vessel spills on the floor.

Your task is to simulate pouring water into the vessels. To do this, you will need to handle two types of queries:

  1. Add x__i liters of water to the p__i-th vessel;
  2. Print the number of liters of water in the k__i-th vessel.

When you reply to the second request you can assume that all the water poured up to this point, has already overflown between the vessels.

有 n 个容器按自上而下的顺序排列,如下图所示。假设容器编号为 1 到 n,从最上方的容器到最下方的容器依次编号,第 i 个容器的容积为 a__i 升。

初始时,所有容器均为空。向某些容器中注入水。从第 i 个容器溢出的所有水将全部流入第 (i + 1) 个容器;从第 n 个容器溢出的水则流到地面。

你的任务是模拟向容器中注水的过程。为此,你需要处理两类查询:

  1. 向第 p__i 个容器中加入 x__i 升水;
  2. 输出第 k__i 个容器中当前的水量(单位:升)。

在响应第二类查询时,你可以假定截至该时刻所注入的所有水均已按规则在容器间完成溢流。

输入格式

The first line contains integer n — the number of vessels (1 ≤ n ≤ 2·105). The second line contains n integers _a_1, _a_2, ..., a__n — the vessels' capacities (1 ≤ a__i ≤ 109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The third line contains integer m — the number of queries (1 ≤ m ≤ 2·105). Each of the next m lines contains the description of one query. The query of the first type is represented as "1 p__i x__i", the query of the second type is represented as "2 k__i" (1 ≤ p__i ≤ n, 1 ≤ x__i ≤ 109, 1 ≤ k__i ≤ n).

第一行包含一个整数 nn —— 船只的数量(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)。
第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n —— 各船只的容量(1≤ai≤1091 \leq a_i \leq 10^9)。船只的容量不一定从上到下递增(参见第二个样例)。
第三行包含一个整数 mm —— 查询的数量(1≤m≤2⋅1051 \leq m \leq 2 \cdot 10^5)。
接下来的 mm 行,每行描述一个查询。第一类查询表示为 1 p_i x_i,第二类查询表示为 2 k_i(其中 1≤pi≤n1 \leq p_i \leq n,1≤xi≤1091 \leq x_i \leq 10^9,1≤ki≤n1 \leq k_i \leq n)。

输出格式

For each query, print on a single line the number of liters of water in the corresponding vessel.

对于每个查询,在一行中输出对应容器中的水量(单位:升)。

输入输出样例

  • 输入#1

    2
    5 10
    6
    1 1 4
    2 1
    1 2 5
    1 1 4
    2 1
    2 2

    输出#1

    4
    5
    8
  • 输入#2

    3
    5 10 8
    6
    1 1 12
    2 2
    1 1 6
    1 3 2
    2 2
    2 3

    输出#2

    7
    10
    5

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

首页