시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB125746457.143%

문제

There is a graph with a total of $2N$ vertices. There are no edges between the $1$st and $N$-th vertices, and there are no edges between the $(N+1)$-th and $2N$-th vertices. That is, the given graph is a bipartite graph.

A sequence of positive integers $a_1, a_2, \cdots, a_N$ is given. For any $(i,j)$ pair with $1 \le i, j \le N$, the necessary and sufficient condition for vertices $i$ and $N+j$ to be connected is that $j \le a_i$.

A total of $Q$ queries are given. Each query is represented by two integers $v$ and $x$, indicating that the value of $a_v$ will be changed to $a_v + x$. It is guaranteed that $x = 1$ or $x = -1$. For each query, you must count the number of cycles of length $4$ in the given graph. Since the count may be large, output the remainder when divided by $998\,244\,353$. Two cycles are considered different if the sets of edges composing them are different.

입력

The first line contains two positive integers $N$ and $Q$, separated by a space.

The second line contains a total of $N$ integers $a_1, a_2, \cdots, a_N$, separated by spaces.

The next $Q$ lines each contain two integers $v$ and $x$ separated by a space. The input on the $i$th line indicates that $a_v$ will be changed to $a_v + x$.

출력

After each query is executed, output the remainder when the number of cycles of length $4$ is divided by $998\,244\,353$ on each line.

제한

  • $1 \le N \le 500\,000$, $1\le Q\le 500\,000$
  • For each queries, $1 \le v \le N$ and $x \in \left\{ -1, 1 \right\}$.
  • After each queries, it is guaranteed that $0\le a_i\le N$ for all $1\le i\le N$.

예제 입력 1

10 10
8 6 1 3 0 0 6 9 6 1
6 1
10 -1
5 1
7 -1
7 -1
9 -1
8 -1
7 -1
7 -1
5 -1

예제 출력 1

178
178
178
158
142
127
127
115
105
105

노트

The set of four edges $\left\{ xy,yz,zw,wx\right\}$ in a graph is considered to be a cycle of length $4$.

채점 및 기타 정보

  • 예제는 채점하지 않는다.