#K51167. Smallest Subsequence Sorting

    ID: 29028 Type: Default 1000ms 256MiB

Smallest Subsequence Sorting

Smallest Subsequence Sorting

Given an integer sequence, your task is to identify the smallest contiguous subsequence such that if you sort this subsequence, the entire sequence will become sorted in non-decreasing order. Formally, let ( A = [a_0, a_1, \dots, a_{n-1}] ) denote the sequence. You need to find indices ( i ) and ( j ) (with ( 0 \leq i \leq j < n )) such that sorting the subarray ( A[i \ldots j] ) makes the whole array sorted. If the sequence is already sorted, output ( 0\ 0 ).

inputFormat

The input is given via standard input (stdin). The first line contains a single integer ( T ) indicating the number of test cases. Each test case consists of two lines: the first line contains an integer ( N ) (the length of the sequence), and the second line contains ( N ) integers representing the sequence elements separated by spaces.

outputFormat

For each test case, output one line with two space-separated integers ( i ) and ( j ) which denote the starting and ending indices (0-based) of the minimal subsequence that must be sorted so that the entire sequence becomes sorted.## sample

2
7
1 3 5 4 2 6 7
5
1 2 3 4 5
1 4

0 0

</p>