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

#FT0000215. Thao tác vô hạn (Infinite Operations)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Thao tác vô hạn (Infinite Operations)

Infinite Operations

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a sequence of NN positive integers A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) and QQ point updates. After each update, answer the following optimization problem for the updated sequence.

A legal operation is performed as follows:

  1. Choose indices i,ji,j satisfying Ai≤AjA_i\le A_j.
  2. Choose a nonnegative real number xx satisfying Ai+2x≤AjA_i+2x\le A_j.
  3. Increase AiA_i by xx, decrease AjA_j by xx, and earn xx points.

Operations may be repeated on the resulting sequence. Let f(t)f(t) denote the maximum total points obtainable by performing exactly tt operations. The limit lim⁡t→∞f(t)\lim_{t\to\infty} f(t) is guaranteed to exist and to be rational.

Output this limit modulo 998244353998244353 after each update. More precisely, if the limit is the reduced fraction P/DP/D, print the unique integer RR in [0,998244352][0,998244352] satisfying

R⋅D≡P(mod998244353).R\cdot D\equiv P\pmod{998244353}.

The existence and uniqueness of RR is guaranteed. Each answer starts from the sequence just after its point update, not from an intermediate state of any previous optimization process.

Input

  • The first line contains two integers N,QN,Q, the sequence length and number of updates.
  • The second line contains NN positive integers A1,A2,…,ANA_1,A_2,\ldots,A_N.
  • Each of the next QQ lines contains two integers xi,yix_i,y_i, setting Axi=yiA_{x_i}=y_i. Indices are one-based.

Output

Print exactly QQ lines. Line ii contains the limiting maximum score after the ii-th point update, reduced modulo 998244353998244353 using the rational-number convention defined above.

Subtasks

  • Subtask 1 (20 points): 2≤N≤82\le N\le 8; 1≤Q≤301\le Q\le 30; 1≤Ai≤1091\le A_i\le 10^9 for every 1≤i≤N1\le i\le N; 1≤xi≤N1\le x_i\le N and 1≤yi≤1091\le y_i\le 10^9 for each 1≤i≤Q1\le i\le Q.
  • Subtask 2 (30 points): 2≤N≤30002\le N\le 3000; 1≤Q≤30001\le Q\le 3000; 1≤Ai≤1091\le A_i\le 10^9 for every 1≤i≤N1\le i\le N; 1≤xi≤N1\le x_i\le N and 1≤yi≤1091\le y_i\le 10^9 for each 1≤i≤Q1\le i\le Q.
  • Subtask 3 (50 points): 2≤N≤3000002\le N\le 300000; 1≤Q≤3000001\le Q\le 300000; 1≤Ai≤1091\le A_i\le 10^9 for every 1≤i≤N1\le i\le N; 1≤xi≤N1\le x_i\le N and 1≤yi≤1091\le y_i\le 10^9 for each 1≤i≤Q1\le i\le Q.

Examples

Example 1

Input

3 4
7 5 5
1 5
2 6
1 7
3 5

Output

0
1
2
2

Explanation

After the four assignments the sequence is (5,5,5)(5,5,5), (5,6,5)(5,6,5), (7,6,5)(7,6,5), and (7,6,5)(7,6,5). The pairwise absolute-difference sums are respectively 00, 22, 44, and 44, so their halves are 00, 11, 22, and 22. The last assignment leaves the sequence unchanged.

Example 2

Input

2 4
1 2
2 5
1 3
1 2
2 3

Output

2
1
499122178
499122177

Explanation

After the updates, the sequences are (1,5)(1,5), (3,5)(3,5), (2,5)(2,5), and (2,3)(2,3). Their limiting scores are 22, 11, 3/23/2, and 1/21/2. Since the inverse of 22 modulo 998244353998244353 is 499122177499122177, the representations of 3/23/2 and 1/21/2 are 499122178499122178 and 499122177499122177, respectively.