[Solution] Weird Subarrays CodeChef Solution
Problem
An array is called weird if it can be sorted by applying the given operation any number of times:
- Select any index and set .
For example: is weird since after applying the operation at , becomes which is sorted.
JJ has a permutation of length . He wants to find the number of subarrays of which are weird. Can you help him?
Input Format
- The first line contains a single integer — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer — the size of the permutation .
- The second line of each test case contains space-separated integers denoting the permutation .
Output Format
For each test case, output on a new line the number of weird subarrays of .
👇👇👇👇👇
Explanation:
Test Case 1: Weird subarrays of are: .
Test Case 2: Weird subarrays of are: .
No comments:
Post a Comment