#K85712. Array Manipulation Queries
Array Manipulation Queries
Array Manipulation Queries
Given an array of integers, you have to perform a series of queries. There are three types of queries:
- Type 1: Reverse the subarray from index \(l\) to \(r\) (inclusive).
- Type 2: Rotate the array to the right by \(k\) positions. This means that the last \(k\) elements become the first \(k\) elements of the array.
- Type 3: Check if the array is sorted in non-decreasing order. For this query, output "YES" if sorted, otherwise output "NO".
All indices are 0-based. Process the queries in the order they are given. For each type 3 query, print the corresponding result.
The rotation in type 2 is defined mathematically as follows: if \(A = [a_0, a_1, \dots, a_{n-1}]\), then after rotating by \(k\) (where \(0 \le k < n\)), the array becomes \(A' = [a_{n-k}, a_{n-k+1}, \dots, a_{n-1}, a_0, a_1, \dots, a_{n-k-1}]\).
inputFormat
The first line contains a single integer \(T\), the number of test cases. Each test case consists of the following:
- The first line contains two integers \(n\) and \(q\) — the size of the array and the number of queries, respectively.
- The second line contains \(n\) space-separated integers representing the elements of the array.
- Each of the next \(q\) lines contains a query in one of the following formats:
1 l r
— Reverse the subarray from index \(l\) to \(r\) (inclusive).2 k
— Rotate the array to the right by \(k\) positions.3
— Check if the array is sorted in non-decreasing order.
outputFormat
For each test case, print the result of every type 3 query on a separate line. The outputs of different test cases should be printed sequentially in the order of the input.
## sample3
5 3
1 3 5 7 9
1 1 3
2 2
3
5 2
2 4 6 8 10
1 0 4
3
4 3
3 1 2 4
2 1
1 0 2
3
NO
NO
NO
</p>