#P1685E. The Ultimate LIS Problem
The Ultimate LIS Problem
No submission language available for this problem.
Description
It turns out that this is exactly the -th problem of mine that appears in some programming competition. So it has to be special! And what can be more special than another problem about LIS...
You are given a permutation of integers from to . You will have to process updates, where the -th update consists in swapping .
After each update, find any cyclic shift of with , or determine that there is no such shift. (Refer to the output section for details).
Here denotes the length of longest strictly increasing subsequence of .
Hacks are disabled in this problem. Don't ask why.
The first line of the input contains two integers (, ).
The second line of the input contains integers (, all are distinct) — the elements of .
The -th of the next lines contains two integers (, ) — indicating that you have to swap elements in the -th update.
After each update, output any , such that the length of the longest increasing subsequence of doesn't exceed , or , if there is no such .
Input
The first line of the input contains two integers (, ).
The second line of the input contains integers (, all are distinct) — the elements of .
The -th of the next lines contains two integers (, ) — indicating that you have to swap elements in the -th update.
Output
After each update, output any , such that the length of the longest increasing subsequence of doesn't exceed , or , if there is no such .
Samples
Note
After the first update, our permutation becomes . We can show that all its cyclic shifts have .
After the second update, our permutation becomes . We can show that all its cyclic shifts have .
After the third update, our permutation becomes . Its shift by is , and its .
After the fourth update, our permutation becomes . We can show that all its cyclic shifts have .
After the fifth update, our permutation becomes . Its shift by is , and its .
After the fifth update, our permutation becomes . Its shift by is , and its .