#P6107. [Ynoi2010] Worst Case Top Tree
[Ynoi2010] Worst Case Top Tree
Problem Description
Given a sequence .
It satisfies , and are given in the input.
For , define that and are adjacent, and and are adjacent.
If and are adjacent, then and are also adjacent.
If , and is adjacent to , is adjacent to , and all are distinct, then the set is called a 6-cycle (that is, when judging whether two 6-cycles are the same, the order of is not considered).
There are modification operations. Each operation gives , and changes to .
After each modification, you need to output the number of 6-cycles.
Input Format
The first line contains an integer .
The second line contains integers .
The third line contains an integer .
The next lines each contain two integers , describing one modification operation.
Output Format
Output lines. Each line contains one integer, the number of 6-cycles after each modification.
6
1 2 5 4 3 6
4
1 8
3 6
5 10
2 7
3
0
1
1
Hint
Idea: ccz181078, Solution: ccz181078, Code: ccz181078&zx2003, Data: nzhtl1477&zx2003.
For of the testdata, all values mentioned above are integers, and $1 \le n,m \le 5 \cdot 10^5;\;1 \le x \le n;\;1 \le a_i,y \le 10^9$.
Translated by ChatGPT 5