#K38187. Counting Rearrangeable Subarrays
Counting Rearrangeable Subarrays
Counting Rearrangeable Subarrays
You are given an array of integers. In one operation, you can rearrange any subarray in any order. Since any subarray can always be rearranged into a non-decreasing order, the answer for each test case is simply the total number of subarrays of the array.
Recall that for an array of length \(n\), the total number of subarrays is given by the formula: \[ \frac{n(n+1)}{2} \]
Your task is to compute this number for each test case.
inputFormat
The first line contains an integer \(T\) denoting the number of test cases. Each test case consists of two lines:
- The first line contains a single integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
For each test case, output a single line containing the total number of subarrays that can be rearranged to form a non-decreasing sequence. (This number is \(\frac{n(n+1)}{2}\)).
## sample2
4
4 1 3 2
3
3 1 2
10
6
</p>