Under construction

Still being built. Things may change

Flowing Fountain

Interview

Time limit5sMemory limit2048 MB

Summary
Champagne poured into a level spills into the first lower level with a larger capacity, and the task is to answer how much each level holds.
Level

Medium6 of 10

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

Problem

Last week, Bill filled a champagne fountain for the first time. Delighted by the champagne pouring from one glass into another, he decided to organize an even bigger champagne fountain for the next World Finals. He has already ordered nn glass bowls with different capacities to stack on top of each other into a huge glass fountain. However, he is still unsure how to pour the champagne into it. One bottle will not be enough, and pouring from the top might not fill every bowl. Bill wants to try out different ways to fill the fountain, but wasting any champagne would be a shame.

The iith image visualizes the iith query of type '+'.

You are tasked with writing a program that simulates pouring champagne into a given fountain. If a bowl in some level is already full, the champagne spills over to the first level below it with a larger capacity. If that level is also full, the champagne spills further down, until it seeps into the ground and is wasted. Bill also wants to know, at certain points in the simulation, how much champagne is in a given level.

Input

The first line has two integers nn and qq (1≤n,q≤3⋅1051\leq n, q \leq 3 \cdot 10^5), the number of levels and the number of queries.

The second line has nn distinct integers cc (1≤c≤1091\leq c \leq 10^9), the capacity of each level in litres. The levels are given from top to bottom.

Each of the next qq lines describes a query. The first symbol tt is either '+' or '?'.

  • If tt is '+', two integers ℓ\ell and xx follow (1≤ℓ≤n1 \leq \ell \leq n, 1≤x≤1091 \leq x \leq 10^9). Bill pours xx litres of champagne into level ℓ\ell.
  • If tt is '?', one integer ℓ\ell follows (1≤ℓ≤n1 \leq \ell \leq n). Bill requests the current amount of champagne in level ℓ\ell in litres.

It is guaranteed that there is at least one query of type '?'.

Output

For each query of type '?', output the amount of champagne in the requested level in litres.

Examples2

  1. Example 1

    Input
    4 4
    1 2 3 4
    + 1 6
    ? 4
    + 1 6
    ? 4
    
    Expected output
    0
    4
    
  2. Example 2

    Input
    4 8
    2 4 3 5
    + 1 4
    ? 2
    + 2 3
    ? 4
    + 3 4
    ? 4
    + 2 10
    ? 4
    
    Expected output
    2
    1
    2
    5