We are given an array of size 'N' with 'Q' queries. Each query contains 3 integers (A,B and C) which divides the entire array into 4 parts or subarrays, [0,A-1],[A,B],[B+1,C] and [C+1,N-1]. We need to swap first and second subarray and third and fourth subarray.
You need to output the final array after Q queries.
Constraints:
1<=N<=10^5
1<=Q<=10^5
1<=A[i]<=10^9.
Eg:- N=9 with 2 queries
9 2
1 2 3 4 5 6 7 8 9
2 4 6
1 3 5
In first query we are supposed to swap [0,1] and [2,4], [5,6] and [7,8]. So after first query array becomes [3,4,5,1,2,8,9,6,7]
In second query we are supposed to swap [0,0] and [1,3], [4,5] and [6,8] of modified array. So final array is [4,5,1,3,9,6,7,2,8]
How to solve this question?