← Home
write a go solution for Description:
You have an array a of n elements. There are also q modifications of the array. Before the first modification and after each modification, you would like to know the following:

What is the minimum length subarray that needs to be sorted in non-decreasing order in order for the array a to be completely sorted in non-decreasing order?

More formally, you want to select a subarray of the array (l,r) with the minimum value of r-l+1. After that, you will sort the elements a_l,a_l+1,ldots,a_r and want the condition a_i<=a_i+1 to hold for all 1<=i<n. If the array is already sorted in non-decreasing order, then l and r should be considered as equal to -1.

Note that finding such (l,r) does not change the array in any way. The modifications themselves take the form: assign a_pos=x for given pos and x.

Input Format:
Each test consists of several test cases. The first line contains an integer t (1<=t<=10) — the number of test cases. Then follows the description of test cases.

The first line of each test case contains a single integer n (1<=n<=5*10^5).

The second line of each test case contains n integers a_i (0<=|a_i|<=10^9) — the initial elements of the array a.

The third line of each test case contains a number q (0<=q<=5*10^5) — the number of modifications to the array.

The following q lines of each test case contain two integers pos_i (1<=pos_i<=n) and val_i (0<=|val_i|<=10^9) — this means that for the i-th modification, a_pos_i is assigned the value val_i.

It is guaranteed that the sum of n and the sum of q for all test cases does not exceed 5*10^5.

Output Format:
For each test case, output q+1 lines. Each line should contain 2 integers l,r — the boundaries of the minimum subarray, such that sorting it will make the array a completely sorted. If a is already sorted, then output l=-1, r=-1.

Note:
Let's consider the first test case:

- Initially, the array is sorted in non-decreasing order: [2,2,3,4,5]
- After the first query, the array looks like this: [colorred2,colorred1,3,4,5].
- After the second query, the array looks like this: [colorred2,colorred1,colorred3,colorred1,5].
- After the third query, the array looks like this: [1,1,colorred3,colorred1,5].

The red segments indicate the subarrays that need to be sorted in order for the entire array to be sorted in non-decreasing order.. Output only the code with no comments, explanation, or additional text.