No.833 Cool Train
Problem Statement
Shuz*-kun has a toy train consisting of $N$ cars, numbered from $1$ to $N$.
Each car $i$ has a coolness value $A_i$.
With this toy, car $i$ and car $i + 1$ can be connected and separated.
Shuz*-kun is playing with this toy, and from time to time he wants to check the coolness of the connected cars.
Initially, all cars are separated.
Write a program that can process the following queries.
1. connect $x$
If car $x$ and car $x+1$ are not connected, connect them.
2. separate $x$
If car $x$ and car $x+1$ are connected, separate them.
3. remodel $x$
Car $x$ has been remodeled, and as a result the coolness of car $x$ increased by $1$.
4. attractiveness $x$
Output the total coolness of car $x$ and all cars connected to it.
Constraints
Input
$N\ Q$ $A_1\ A_2\ \dots\ A_N$ $query_1\ x_1$ $query_2\ x_2$ $\vdots$ $query_Q\ x_Q$
Output
For each attractiveness query, output the coolness on one line. Print a newline at the end.
Sample
Sample 1
Input
2 7 1 3 4 1 4 2 1 1 4 1 4 2 3 1 4 1
Output
1 3 4 4 5
Sample 2
Input
10 10 1 3 10 20 3 4 12 41 2 40 1 2 1 4 1 5 4 1 4 4 3 2 1 3 2 5 4 2 4 6
Output
1 27 37 4
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tatyam