#P8505. 「CGOI-2」No voice to cry suffering

「CGOI-2」No voice to cry suffering

Background

Father, your kingdom is collapsing.

Father, your people are leaving.

Father, but you said I should not have a voice to cry for suffering.

So I can do nothing, so I fall apart alone.

Problem Description

There are nn infected people in front of the container. These nn infected people stand in a line, numbered from 11 to nn in order. The infection depth of the ii-th infected person is aia_i.

The container starts from the xx-th infected person and walks towards the nn-th infected person, passing through the infected people from xx to nn in order. The container will kill all infected people it passes. However, if it kills two infected people whose indices are consecutive and whose infection depths are strictly increasing, then it will skip the next infected person (if the next one exists).

Let fxf_x denote the number of infected people killed when the container starts from position xx (all ff are pairwise independent). For example, if there are five infected people with infection depths:

2 6 4 5 1

then the corresponding ff sequence is {4,3,2,2,1}\{4,3,2,2,1\}.

You do not know the infection depth of each infected person. You only know the values of fifi+1f_i-f_{i+1} for mm pairs. Please output, modulo 998244353998244353, the number of different ff sequences that satisfy the conditions.

Two sequences f,gf,g are different if and only if there exists 1in1 \le i \le n such that figif_i \not= g_i.

Input Format

The first line contains two integers n,mn,m.

In the next mm lines, each line contains a pair (x,y)(x,y), meaning fxfx+1=yf_x-f_{x+1}=y.

Note that the input may contain incorrect pairs, and you need to ignore them by yourself. Specifically, if a pair (xi,yi)(x_i,y_i) makes it impossible to have any valid ff sequence after considering all valid pairs among 1i11 \sim i-1 and this pair, then this pair is invalid, and you should not consider it when computing the answer.

Output Format

Output (m+1)(m+1) lines, one number per line.

The first line is the answer modulo 998244353998244353 when no pairs are considered.

The ii-th line (2im+12 \le i \le m+1) is the answer modulo 998244353998244353 after considering all valid pairs among 1i11 \sim i-1.

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

Hint

Explanation for Sample 1

Initially, the valid ff sequences are {3,2,1}\{3,2,1\} and {2,2,1}\{2,2,1\}.

Constraint 1: None of the initial ff sequences satisfies constraint 1, so ignore this constraint.

Constraint 2: Only {3,2,1}\{3,2,1\} satisfies the constraint.

Constraint 3: Only {2,2,1}\{2,2,1\} satisfies the constraint. Together with constraint 2, there is no valid ff sequence, so ignore this constraint.


Constraints and Notes

For 20%20\% of the testdata, n,m5n,m \le 5.

For 60%60\% of the testdata, n106n \le 10^6.

For another 10%10\% of the testdata, m=0m=0.

For 100%100\% of the testdata, $1 \leq n \leq 10^{11}, 0 \leq m \leq 5\times 10^4, 0 \leq |y| \leq n, 1 \leq x < n$.

Translated by ChatGPT 5