luogu#P4868. Preprefix sum

Preprefix sum

Problem Description

The prefix sum is defined as Si=k=1iakS_i=\sum_{k=1}^i a_k.

The preprefix sum (preprefix sum) takes SiS_i as the original sequence and computes the prefix sum again. Let the ii-th value of this second prefix sum be SSiSS_i.

Given a sequence a1,a2,,ana_1, a_2, \cdots, a_n of length nn, there are two types of operations:

  1. Modify i x: Change aia_i to xx.
  2. Query i: Query SSiSS_i.

Input Format

The first line contains two integers N,MN, M, representing the length of the sequence and the number of operations.
The next line contains NN numbers, the given sequence a1,a2,,ana_1, a_2, \cdots, a_n.
The next MM lines each contain one operation, with the format described above.

Output Format

For each query operation, output one line containing the value of SSiSS_i being queried.

5 3
1 2 3 4 5
Query 5
Modify 3 2
Query 5
35
32

Hint

Constraints: 1N,M1051\le N,M\le 10^5, and at any time 0Ai1050\le A_i\le 10^5.

Translated by ChatGPT 5