P9436 『XYGOI round1』Some Numbers
Background
MX is studying the properties of permutations. One day, she took out $n$ cards and lined them up, wanting to fill numbers on them to form a permutation of $1\sim n$.
While MX was not paying attention, Piggy secretly wrote numbers on some cards.
Description
MX soon noticed all of this. However, she was not angry. Instead, she thought about an interesting problem: if she fills some numbers so that it is still a permutation, and its longest increasing subsequence has length $n-1$, how many ways are there to fill the numbers?
Piggy is fairly decent. He did not write the same number in different positions.
Input Format
This problem contains multiple test cases.
The first line contains an integer $T$, representing the number of test cases.
For each test case:
- The first line contains two integers $n,q$, representing the number of cards and how many numbers Piggy has already filled in.
- The second line contains $2q$ integers. The $(2i-1)$-th and $(2i)$-th integers $(x,y)$ mean that the $x$-th number is filled as $y$ by Piggy.
Output Format
Output $T$ lines, each line containing one integer representing the answer.
Explanation/Hint
#### Sample Explanation
Use $-1$ to represent that the number at this position has not been determined yet.
Sample $1$: the permutation given in the first test case is $-1,2,-1,8,-1,5,6,-1,-1,-1$. It is easy to see that only $1,2,3,8,4,5,6,7,9,10$ has a longest increasing subsequence length of $10-1=9$. The permutation given in the second test case is $-1,-1$, and $2,1$ is the only sequence that satisfies the requirement.
**This problem uses bundled tests.**
| Subtask | $\sum n$ | $\sum q$ | Score |
|:-:|:-:|:-:|:-:|
|0|$\le 10$|$\le 10$|10|
|1|$\le 15$|$\le 10$|20|
|2|$\le 5\times 10^3$|$\le 5\times 10^3$|30|
|3|$\le 5\times 10^5$|$\le 5\times 10^5$|40|
Constraints: $0\le q\le n$, $1\le n\le 5\times 10^5$, $1\le T\le 10^5$, $1 \le x,y \le n$.
Translated by ChatGPT 5