cho.sh
Notes
Loading...

Coffee Shop Game 2

Time limit

2s

Memory limit

256 MB

Problem

A game is played in a coffee shop.

Initially, there are NNN integers arranged in a row. Each turn has two steps.

  1. Given two positions xxx and yyy, find the sum of the current array from the xxx-th number through the yyy-th number.
  2. Given a position aaa and a value bbb, replace the aaa-th number with bbb.

Write a program that prints the required range sum for every turn.

Input

The first line contains the number of integers NNN and the number of turns QQQ. (1≤N,Q≤100,000)(1 \le N, Q \le 100,000)(1≤N,Q≤100,000)

The second line contains the initial NNN integers in the array.

Each of the next QQQ lines contains four integers xxx, yyy, aaa, and bbb, describing one turn. First find the sum from the xxx-th number through the yyy-th number in the current array, then replace the aaa-th number with bbb.

Every integer in the input is between −231-2^{31}−231 and 231−12^{31}-1231−1, inclusive.

Output

For each turn, output the computed range sum on its own line.

Hint

Normally, x∼yx \sim yx∼y means from the xxx-th number through the yyy-th number. In this problem, if x>yx > yx>y, compute the sum from the yyy-th number through the xxx-th number instead.