Under construction

Still being built. Things may change

Loyalty Game

Interview

Time limit2sMemory limit1024 MB

Summary
Each type 1 query pours x liters from student i onward, with each student drinking up to their capacity, and type 2 asks a student's total drunk amount.
Level

Medium5 of 10

Topics
Union-find, Simulation, Array
Solved
No attempts yet

Problem

Loyalty Game is a game in which NN students, numbered 1 to NN, take turns drinking all of XX liters of liquor in order. Luckily, the students of Hangkong University are very loyal, so each student drinks as much of the liquor passed to them as they can, up to their maximum capacity.

Here, the maximum capacity is the largest amount of liquor a person can drink. When a student drinks up to their maximum capacity, they become drunk, and from then on they forget loyalty and pass the liquor to the next student right away. However, if liquor reaches student NN and they become drunk while drinking it, or they are already drunk, all the liquor is thrown away.

Two kinds of queries are given in time order. The queries accumulate.

  • 1 ii xx: Person ii has xx liters of liquor, and the game runs from person ii to person NN. (1≤i≤N1 \leq i \leq N; 1≤x≤1 000 000 0001 \leq x \leq 1\,000\,000\,000)
  • 2 ii: Print the total amount of liquor student ii has drunk so far. (1≤i≤N1 \leq i \leq N)

Input

The first line contains the number of students NN and the number of queries QQ, separated by a space. (1≤N,Q≤100 0001 \leq N, Q \leq 100\,000)

The next NN lines each contain the maximum capacity mim_i of student ii. (1≤mi≤1091 \leq m_i \leq 10^9; 1≤i≤N1 \leq i \leq N)

From line N+2N + 2, the next QQ lines each contain a query in the format described above.

All given numbers are integers.

Output

For each query of type 2, print the answer on its own line, in the order the queries appear.

Examples1

  1. Example 1

    Input
    2 4
    1
    2
    1 2 1
    2 2
    1 1 3
    2 1
    
    Expected output
    1
    1