luogu#P10807. [LMXOI Round 2] Disaster

[LMXOI Round 2] Disaster

Background

LMX and HQZ are studying how to partition points.

Problem Description

Given nn points, each point provides a pair of constraints li,ri(0li<i<rin+1)l_i, r_i (0 \le l_i < i < r_i \le n+1). A partition is defined to be good if and only if, for every point ii, after partitioning, both lil_i and rir_i are not in the same interval as ii. Find the number of good partitions. Output the answer modulo 998244353998244353.

Supplement: In this problem, a partition means dividing the nn points into several intervals such that each point belongs to exactly one interval. li=0l_i = 0 and ri=n+1r_i = n+1 can be considered as no constraint.

Input Format

The first line contains an integer nn, which represents the number of points.

The next nn lines each contain two integers li,ril_i, r_i on the ii-th line.

Output Format

Output one integer on the first line, which is the answer modulo 998244353998244353.

5
0 3
0 3
1 6
2 6
2 6
8

Hint

Sample Explanation #1

The 88 legal interval partitions in the sample are:

[1,2],[3,5][1,2],[3,5]

[1,1],[2,2],[3,5][1,1],[2,2],[3,5]

[1,2],[3,3],[4,5][1,2],[3,3],[4,5]

[1,1],[2,2],[3,3],[4,5][1,1],[2,2],[3,3],[4,5]

[1,2],[3,4],[5,5][1,2],[3,4],[5,5]

[1,1],[2,2],[3,4],[5,5][1,1],[2,2],[3,4],[5,5]

[1,2],[3,3],[4,4],[5,5][1,2],[3,3],[4,4],[5,5]

[1,1],[2,2],[3,3],[4,4],[5,5][1,1],[2,2],[3,3],[4,4],[5,5]

For all testdata, 1n2×1061 \le n \le 2 \times 10^6, 0li<i<rin+10 \le l_i < i < r_i \le n+1.

Subtask ID nn Special Property Score
Subtask #1 20\le 20 None 55
Subtask #2 500\le 500 1010
Subtask #3 5000\le 5000 2020
Subtask #4 5×105\le 5 \times 10^5 li=0l_i = 0 1010
Subtask #5 None 2525
Subtask #6 2×106\le 2 \times 10^6 3030

Translated by ChatGPT 5