Time limit: 1.5s
Memory limit: 128MB
Input:
Output:
Task
You are given an array of elements.
You need to perform operations, where operation represents reversing the subsequence .
Input data
The first line contains two integers and , representing the length of the array and the number of operations.
The second line contains numbers, representing the elements of the array .
Each of the next lines contains 2 integers and , representing the subsequence that will be reversed in operation .
Output data
On a single line, print the elements of the array after applying the operations in the order they were read.
Constraints and notes
- It is recommended to use the following line of code at the beginning of the
main
function, to reduce input data reading time:cin.tie(0)->sync_with_stdio(0);
.
# | Score | Constraints |
---|---|---|
0 | 0 | Examples |
1 | 20 | |
2 | 20 | |
3 | 60 | No additional constraints |
Example 1
stdin
7 2
1 5 2 1 2 4 7
3 4
4 7
stdout
1 5 1 7 4 2 2
Explanation
The array is initially .
After the first operation, the array becomes .
After the second operation, the array becomes .
Example 2
stdin
8 5
5 2 7 3 1 6 8 4
1 4
2 7
5 8
1 8
2 3
stdout
5 7 2 4 1 6 8 3