PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000021. Tổng tiền tố ba lần (Cumulative Cumulative Cumulative Sum)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng tiền tố ba lần (Cumulative Cumulative Cumulative Sum)

Cumulative Cumulative Cumulative Sum

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a sequence of nonnegative integers A1,A2,…,AnA_1,A_2,\ldots,A_n. From AA, define three cumulatively summed sequences B,C,DB,C,D, for every 1≤i≤n1\le i\le n:

$$B_i=\sum_{j=1}^{i}A_j,\qquad C_i=\sum_{j=1}^{i}B_j,\qquad D_i=\sum_{j=1}^{i}C_j.$$

Process qq commands in order. Command 1 x v replaces AxA_x with vv. Command 2 x asks for DxD_x computed from the current array AA, and prints DxD_x modulo 998244353998244353.

After an assignment, B,C,DB,C,D are understood to be redefined from the updated AA. All three prefix summations begin at index 11. A query does not modify AA.

Input

  • Line 1: n q gives array length and command count.
  • Line 2: A_1 A_2 ... A_n gives the initial values in index order.
  • Next qq lines: each line contains one of the following commands, in execution order:
    • 1 x v: set Ax=vA_x=v.
    • 2 x: query Dx mod 998244353D_x\bmod 998244353.

Output

For every 2 x command, print Dx mod 998244353D_x\bmod 998244353 as one integer in [0,998244352][0,998244352], on a separate line.

Subtasks

Subtask 1 (20 points):

  • 1≤n≤241\le n\le 24.
  • 1≤q≤301\le q\le 30.
  • 0≤Ai,v≤1090\le A_i,v\le 10^9.
  • 1≤x≤n1\le x\le n.
  • query modulus is 998244353998244353.

Subtask 2 (30 points):

  • 1≤n≤12001\le n\le 1200.
  • 1≤q≤16001\le q\le 1600.
  • 0≤Ai,v≤1090\le A_i,v\le 10^9.
  • 1≤x≤n1\le x\le n.
  • query modulus is 998244353998244353.

Subtask 3 (50 points):

  • 1≤n≤2000001\le n\le 200000.
  • 1≤q≤2000001\le q\le 200000.
  • 0≤Ai,v≤1090\le A_i,v\le 10^9.
  • 1≤x≤n1\le x\le n.
  • query modulus is 998244353998244353.

Examples

Input

3 3
1 2 3
2 3
1 2 0
2 3

Output

15
9

Explanation

Initially A=[1,2,3]A=[1,2,3]. All sequences use 1-based indices.

  1. 2 3: the first prefix sums are B=[1,1+2,1+2+3]=[1,3,6]B=[1,1+2,1+2+3]=[1,3,6]. The next are C=[1,1+3,1+3+6]=[1,4,10]C=[1,1+3,1+3+6]=[1,4,10]. Finally D=[1,1+4,1+4+10]=[1,5,15]D=[1,1+4,1+4+10]=[1,5,15]. Thus D3=15D_3=15, unchanged modulo 998244353998244353; print 15.

  2. 1 2 0: assign the second element of AA to 00, replacing its old value 22. Now A=[1,0,3]A=[1,0,3].

  3. 2 3: recompute the cumulative sequences from the updated AA: B=[1,1,4]B=[1,1,4], C=[1,2,6]C=[1,2,6], D=[1,3,9]D=[1,3,9]. Therefore print 9. The earlier result 1515 no longer applies after the assignment.