#P11197. [COTS 2021] 赛狗游戏 Tiket
[COTS 2021] 赛狗游戏 Tiket
Background
Rebirth.
Translated from Izborne Pripreme 2021 (Croatian IOI/CEOI Team Selection) D2T3。。
Problem Description
Three people are watching a greyhound racing game.
Each of them guesses the order in which the dogs cross the finish line. Let be the ID of the dog that finishes in the -th place. We assume there are no ties.
There are dogs, so forms a permutation of . Let the permutation guessed by the -th person be .
Also, the actual finishing order forms a permutation .
Compute the number of pairs that satisfy the following conditions:
- In , is before .
- , either is before in all , or is before in all .
Input Format
The first line contains a positive integer .
The second line contains positive integers describing .
The next three lines: the -th line contains positive integers describing .
Output Format
Output one line with one integer, the answer.
3
2 3 1
1 2 3
1 2 3
2 3 1
1
4
3 1 2 4
4 3 2 1
1 2 3 4
1 2 4 3
0
5
1 3 2 4 5
4 3 5 2 1
4 3 1 2 5
1 2 4 3 5
3
Hint
Sample Explanation
For sample , only satisfies the conditions.
Constraints
For of the testdata, it is guaranteed that:
- .
- , is a permutation of .
- is a permutation of .
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| None | |||
| Yes | |||
| None | |||
Special property: . That is, the first two people guessed the same permutation.
Translated by ChatGPT 5