#K41902. Magical Forest Operations

    ID: 26968 Type: Default 1000ms 256MiB

Magical Forest Operations

Magical Forest Operations

In a magical forest, there are \(N\) mystical trees arranged in a row. Each tree \(i\) initially has \(F_i\) magical fruits. A group of three elves visits the forest and performs a series of actions. The actions are of three types:

  • Type 1: "1 x y" — The elves collect all magical fruits from trees numbered from \(x\) to \(y\) (inclusive), and those trees will have their counts reset to 0. The output for this action is the word "Collected".
  • Type 2: "2 x v" — The elves add \(v\) magical fruits to the \(x\)-th tree.
  • Type 3: "3 x" — The elves query the current number of magical fruits on the \(x\)-th tree. The output for this action is the number of fruits.

Your task is to simulate these operations. Note that the commands are executed sequentially; modifications by earlier commands affect the later ones.

inputFormat

The first line contains two integers \(N\) and \(M\) separated by a space, where \(N\) is the number of trees and \(M\) is the number of actions.

The second line contains \(N\) integers, representing the initial number of magical fruits on each tree.

The following \(M\) lines each contain an action in one of the following formats:

  • "1 x y"
  • "2 x v"
  • "3 x"

The input is provided via standard input (stdin).

outputFormat

For each action of type 1 and type 3, output the result of the operation on a separate line through standard output (stdout). For type 1, output the string "Collected"; for type 3, output the queried number of fruits.

## sample
5 7
3 8 5 6 10
3 2
2 3 4
1 2 4
3 3
3 4
2 5 15
3 5
8

Collected 0 0 25

</p>