The first line contains a single integer βTβ representing the number of test cases.
The first line of each test case will contain a single integer βNβ, which denotes the number of people in the row.
The second line of each test case will contain βNβ integers that denote each particular personβs height in the row.
For each test case, print the number of ways to select three people according to the condition given in the description.
Output for every test case will be printed in a separate line.
You donβt need to print anything; It has already been taken care of. Just implement the given function.
1 <= T <= 10
3 <= N <= 100
1 <= ARR[i] <= 10 ^ 5
Where 'ARR[i]' denotes the height of the i-th people in the row.
Time limit: 1 sec
The basic idea is to iterate through all possible triplet of people in the row using three loops.
The steps are as follows:
The basic idea of this approach is to calculate the number of possible triplets of people, which follows the required condition by calculating the number of people with less height than the βi-thβ people on his left side and the number of people with greater height on his right side.
The steps are as follows:
The basic idea of this approach is to pre-calculate the number of people with less height on the left side of each individual people and the number of people with the greater height on the right side of each people, this is done by using a segment tree first for the left side and then for the right side. Here, the elements of the array are not changing and so, we will use the offline approach.
Additional Functions Used:
Additional Variables Used:
The steps are as follows:
Ninja And The LCM
A Number Game
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Co-Prime