Problems > Bigger Than X, in a Slice

Bigger Than X, in a Slice

Difficulty: 2100 6000 ms 128 MB

binary-search segment-tree

Answer Q queries (l, r, x): how many elements of al..r are strictly greater than x? The array never changes.

Input: the first line has N and Q; the second line has the array; the next Q lines have l r x.

Output: one line per query.

Constraints:

  • 1 ≤ N, Q ≤ 105
  • |values|, |x| ≤ 106

Sample Tests

Input 1
5 2
1 5 2 4 3
1 3 1
2 5 3
Output 1
2
2
Input 2
1 1
7
1 1 7
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.