#P11017. [2016杭电多校]Memento Mori
[2016杭电多校]Memento Mori
Memento Mori
Problem Description
Professor Zhang has an zero matrix(i.e. a matrix consisting of all 0s). Professor Zhang changes elements in the matrix into 1. Given a permutation of , Professor Zhang wants to find the number of such submatrices that:
- the number of 1s in the submatrix is exactly 4.
- let the positions of the 1s in the submatrix be , then and for all .
- no other submatrices inside the submatrix meet the above two conditions.
Input
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case: The first line contains three integers , and -- the size of the matrix and the number of 1s. The second line contains four integers denoting the permutation. Each of the next lines contains two integers and -- the position of the -th 1. No two 1s will be in the same position.
Output
For each test case, output an integer denoting answer.
Sample Input
1
5 5 4
1 2 3 4
1 1
2 2
3 3
4 4
Sample Output
1
Author
zimpha
Source
2016 Multi-University Training Contest 2