Kamui

시간 제한2초메모리 제한1024 MB

요약
차수를 배열로 유지하면서 한 원소씩 늘리거나 줄이는 질의마다 이분 그래프에 생기는 길이 4 사이클의 개수를 구한다.
난이도

어려움10점 중 8점

유형
수학, 조합론, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

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

A sequence of positive integers a_1,a_2,⋯ ,a_Na\_1, a\_2, \cdots, a\_N is given. For any (i,j)(i,j) pair with 1≤i,j≤N1 \le i, j \le N, the necessary and sufficient condition for vertices ii and N+jN+j to be connected is that j≤a_ij \le a\_i.

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

입력

The first line contains two positive integers NN and QQ, separated by a space.

The second line contains a total of NN integers a_1,a_2,⋯ ,a_Na\_1, a\_2, \cdots, a\_N, separated by spaces.

The next QQ lines each contain two integers vv and xx separated by a space. The input on the iith line indicates that a_va\_v will be changed to a_v+xa\_v + x.

출력

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

제한

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

힌트

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

예제1

  1. 예제 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
    
    예상 출력
    178
    178
    178
    158
    142
    127
    127
    115
    105
    105