#P8895. 「DPOI-1」优美的序列
「DPOI-1」优美的序列
Background
Update on 2022.12.18: Added one set of hack testdata targeting https://www.luogu.com.cn/user/421155
Update on 2022.12.18: Added one set of hack testdata targeting @大眼仔Happy, placed at #22, worth points.
Update on 2025.7.7: Added two sets of hack testdata from ticket https://www.luogu.com.cn/ticket/XQCA458514, placed at #23 and #24. #21 to #24 are all changed to points.
No, Commander-in-Chief.
Problem Description
The Commander-in-Chief gives you a sequence of length .
He thinks that this may not be beautiful enough, and he wants to reorder it into a sequence to make it beautiful.
We call a sequence of length beautiful if and only if such that:
- , .
- , .
He orders you to find how many different can be obtained by reordering . Since the result may be very large, you only need to output it modulo .
A fixed is too boring, so he gives you modifications. Each modification is of the form x k, meaning set . You need to output the current answer after each modification.
Input Format
The first line contains three integers .
The second line contains integers .
The next lines each contain two integers , representing one modification operation.
Output Format
Output a total of lines. Each line contains one integer, representing the required value for the initial state and after each modification.
4 1 998244353
1 2 2 3
3 4
2
8
见下发文件 sequence2.in
见下发文件 sequence2.out
Hint
Explanation for Sample #1
For the initial state, the valid are , for a total of .
For after the first modification, the valid are $[1, 2, 3, 4], [2, 1, 3, 4], [3, 1, 2, 4], [4, 1, 2, 3], [3, 2, 1, 4], [4, 2, 1, 3], [4, 3, 1, 2], [4, 3, 2, 1]$, for a total of .
Explanation for Sample #2
This sample satisfies the constraints of test points .
Constraints
| Test Point ID | Special Condition | ||
|---|---|---|---|
| None | |||
| is a permutation | |||
| None | |||
For of the data, , , , and .
Translated by ChatGPT 5