#C8822. Minimum Operations to Sort Sequence

    ID: 52847 Type: Default 1000ms 256MiB

Minimum Operations to Sort Sequence

Minimum Operations to Sort Sequence

You are given T test cases. In each test case, you are provided with a sequence of N integers. Your task is to determine the minimum number of operations required to transform the sequence into a non-decreasing sequence.

A sequence \(a_1, a_2, \ldots, a_N\) is considered non-decreasing if it satisfies the condition \(a_i \leq a_{i+1}\) for all \(1 \leq i < N\). In this problem, you should output 0 if the sequence is already non-decreasing; otherwise, output 1 indicating that one operation is required.

Note: The allowed operation is predefined in the problem such that any sequence which is not already non-decreasing can be corrected in one operation.

inputFormat

The first line of input contains an integer T representing the number of test cases.

For each test case, the first line contains an integer N representing the number of elements in the sequence. The second line contains N space-separated integers.

Input Format Example:

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

outputFormat

For each test case, output a single line containing a single integer: 0 if the sequence is already non-decreasing and 1 otherwise.

Output Format Example:

1
1
0
## sample
3
5
3 1 2 4 5
4
6 5 4 3
3
1 2 3
1

1 0

</p>