Introduction - If you have any usage issues, please Google them yourself
FancyCoder raises problem called "Reverse K-th Problem". The description is also simple: given an array of N integers A[1],A[2],...,A[n] and some queries, each query asks for the number of continuous subsequences of the array in which the K-th largest element is X.
The first line contains an integer T (1 <= T <= 5), indicating the number of test cases.
For each test case:
The first line contains two integers N and Q (1 <= N <= 2,000, 1 <= Q <= 2,000,000), indicating there are N integers in the array and Q queries.
The second line contains N integers between 1 and N, indicating the element of the array.
Then Q lines follow, the i-th line contains two integers Ki and Xi (1 <= Ki,Xi <= N), indicating that the i-th query asks for the number of continuous subsequences of the array in which the Ki-th largest element is Xi.
For each test case:
Output Q lines, the i-th line contains one integer, indicating the answer to the i-th query.