{"raw_statement":[{"iden":"problem statement","content":"Given are a sequence of $N$ positive integers $A = (A_1, A_2, \\ldots, A_N)$ and $Q$ queries. The $i$\\-th query is as follows:\n\n*   given integers $x_i$ and $y_i$ (where $1\\leq x_i\\leq N$), change $A_{x_i}$ to $y_i$.\n\nEach time the query changes the sequence, find the answer to the following problem modulo $998244353$ (see Notes).\n\n> Let $f(n)$ be the maximum total number of points when doing the following operation $n$ times on $A$.\n> \n> *   Choose $i, j$ such that $A_i\\leq A_j$ and choose **non-negative real number** $x$ such that $A_i + 2x \\leq A_j$.\n> *   Add $x$ to $A_i$ and subtract $x$ from $A_j$.\n> *   Gain $x$ points.\n> \n> It can be proved that the limit $\\displaystyle \\lim_{n\\to\\infty} f(n)$ exists. Find this limit."},{"iden":"notes","content":"We can prove that the limit in question is always a rational number. Additionally, under the Constraints of this problem, when that number is represented as $\\frac{P}{Q}$ using two coprime integers $P$ and $Q$, we can prove that there is a unique integer $R$ such that $R\\times Q\\equiv P\\pmod{998244353}$ and $0\\leq R < 998244353$. Find this $R$."},{"iden":"constraints","content":"*   $2\\leq N\\leq 3\\times 10^5$\n*   $1\\leq Q\\leq 3\\times 10^5$\n*   $1\\leq A_i \\leq 10^9$\n*   $1\\leq x_i\\leq N$\n*   $1\\leq y_i\\leq 10^9$"},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$ $Q$\n$A_1$ $A_2$ $\\ldots$ $A_N$\n$x_1$ $y_1$\n$\\vdots$\n$x_Q$ $y_Q$"},{"iden":"sample input 1","content":"3 4\n7 5 5\n1 5\n2 6\n1 7\n3 5"},{"iden":"sample output 1","content":"0\n1\n2\n2\n\nThe first query changes the sequence to $(5, 5, 5)$. Here, we have $f(n) = 0$ for any $n$, so the answer is $0$.\nThe second query changes the sequence to $(5, 6, 5)$. Here, one possible way to do the operations is as follows.\n\n*   Choose $(i,j,x) = (3,2,0.4)$, changing the sequence to $(5, 5.6, 5.4)$ and gaining $0.4$ points.\n*   Choose $(i,j,x) = (1,2,0.3)$, changing the sequence to $(5.3, 5.3, 5.4)$ and gaining $0.3$ points.\n\nThe above two operations gain $0.7$ points, from which we can see that $f(2) \\geq 0.7$.\nWe can prove that it is impossible to gain more than $1$ point in total, and that the total number of points that can be gained by the optimal way to do the operations tends to $1$ as the number of operations increases. Thus, we have $\\displaystyle \\lim_{n\\to\\infty} f(n) = 1$."},{"iden":"sample input 2","content":"2 4\n1 2\n2 5\n1 3\n1 2\n2 3"},{"iden":"sample output 2","content":"2\n1\n499122178\n499122177"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}