atcoder#ABC279E. [ABC279E] Cheating Amidakuji
[ABC279E] Cheating Amidakuji
Score : points
Problem Statement
You are given a sequence of length consisting of integers between and , inclusive: . Answer the following question for .
- There is a sequence . Initially, we have for each . Let us perform the following operation for in this order (in other words, for integers between and except in ascending order).- Swap the values of and .
- Swap the values of and .
- After all the operations, let be the value of such that . Find .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the value as an integer.
5 4
1 2 3 2
1
3
2
4
For , the operations change as follows.
- Initially, .
- Perform the operation for . That is, swap the values of and , making .
- Perform the operation for . That is, swap the values of and , making .
- Perform the operation for . That is, swap the values of and , making .
After all the operations, we have , so .
Similarly, we have the following.
- For : performing the operation for in this order makes , so .
- For : performing the operation for in this order makes , so .
- For : performing the operation for in this order makes , so .
3 3
2 2 2
1
1
1
10 10
1 1 1 9 4 4 2 1 3 3
2
2
2
3
3
3
1
3
4
4