#d1108. 数数

数数

Counting Queries

Problem Description

Given an array {A}\{A\} of length NN, answer QQ queries asking for the number of elements in the interval [Li,Ri][L_i, R_i] that are not greater than HiH_i.

There are TT test cases in total.

Input Format

The input is formatted as follows:

T
N Q
A1 A2 A3 ... AN
L1 R1 H1
L2 R2 H2
...
LQ RQ HQ
...

Output Format

For the TT test cases, output one line per case containing QQ space-separated integers — the answers.

Sample Input

1
10 3
0 5 2 7 5 4 3 8 7 7
3 9 6
4 6 0
2 4 2

Sample Output

4 0 1

Sample note: $A[3..9] = [\underline{2}, 7, \underline{5, 4, 3}, 8, 7]$, among which the number of elements not greater than 66 is 44.

Constraints

  • 1≤N,Q≤1051 \le N, Q \le 10^5
  • 0≤Ai,H≤1090 \le A_i, H \le 10^9
  • 1≤L≤R≤N1 \le L \le R \le N

Data guarantee: ∑N,Q≤105\sum N, Q \le 10^5