CF371D.Vessels

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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

Initially, all the vessels are empty. In some vessels water is poured. All the water that overflows from the ii -th vessel goes to the (i+1)(i+1) -th one. The liquid that overflows from the nn -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 xix_{i} liters of water to the pip_{i} -th vessel;
  2. Print the number of liters of water in the kik_{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.

输入格式

The first line contains integer nn — the number of vessels ( 1<=n<=21051<=n<=2·10^{5} ). The second line contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} — the vessels' capacities ( 1<=ai<=1091<=a_{i}<=10^{9} ). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The third line contains integer mm — the number of queries ( 1<=m<=21051<=m<=2·10^{5} ). Each of the next mm lines contains the description of one query. The query of the first type is represented as " 1 pi xi1 p_{i} x_{i} ", the query of the second type is represented as " 2 ki2 k_{i} " ( 1<=pi<=n1<=p_{i}<=n , 1<=xi<=1091<=x_{i}<=10^{9} , 1<=ki<=n1<=k_{i}<=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
    
首页