#P10756. [COI 2023] Sličnost
[COI 2023] Sličnost
Background
Source: https://hsin.hr/hio2023/.
Problem Description
She was holding a bunch of disgusting, unsettling yellow flowers in her hands. But he ended up falling for her.
According to a well-known theorem, every person's personality can be represented by a permutation of length . Therefore, the personality of our protagonist—the master (Majstor)—can be represented by a permutation . The personality of the lady who caught his eye—Margarita—can be represented by a permutation .
The similarity (sličnost) of two permutations, that is, the happiness level of married life, is defined as follows: choose a subarray of length from permutation , and choose a subarray of length from permutation . Compute the size of the intersection of the elements contained in these two subarrays. Among all possible choices, the maximum such intersection size is the similarity. Here, the intersection is considered in the set sense, meaning the order of numbers inside the subarray does not matter. For example, when , the similarity of permutations and is 2, and this value can be achieved for any pair of chosen subarrays.
Ever since meeting Margarita, the master has been obsessed with the similarity of their permutations, and his personality has therefore become very changeable. Every day, two adjacent elements in his permutation swap positions. Note that this change is permanent, meaning those two elements will remain swapped in the following days. Now, he wants to know the similarity of his and her permutations when he first met her, and also the similarity after the change on each of the next days. In addition, he also wants to know how many pairs of subarrays achieve this maximum similarity. Troubled by love, he asks for your help.
Input Format
The first line contains three integers and .
The second line contains numbers forming the permutation .
The third line contains numbers forming the permutation .
The next lines describe the changes. The -th line contains an integer (), meaning that in the master's permutation , the numbers at positions and are swapped.
Output Format
On the first line, output the similarity of the initial permutations, and the number of pairs of subarrays that achieve this similarity.
On the next lines, output the same two values after the change on that day.
2 1 1
1 2
1 2
1
1 2
1 2
4 3 0
2 4 1 3
1 2 3 4
2 4
5 3 3
1 4 3 2 5
4 5 1 2 3
3
1
4
2 5
2 6
3 1
3 1
Hint
Sample Explanation
Explanation of the second sample: in the first permutation, the subarrays of length are and ; in the second permutation, they are and . For the intersections, we have:
- ;
- ;
- ;
- ;
So we can see that the similarity is , and this similarity is achieved by four pairs of subarrays.
Constraints
In all subtasks, , , .
| Subtask | Score | Constraints |
|---|---|---|
| No additional constraints |
Translated by ChatGPT 5