#P10814. Range Count Query

    ID: 12856 Type: Default 1000ms 256MiB

Range Count Query

Range Count Query

You are given a sequence \(a\) of length \(n\) and \(m\) queries. Each query provides three integers \(l\), \(r\) and \(x\), and your task is to compute the number of elements in the subarray \([l, r]\) that are less than or equal to \(x\).

Input Format: The first line contains two integers \(n\) and \(m\). The second line contains \(n\) space-separated integers representing the array \(a\). Then \(m\) lines follow, each containing three integers \(l\), \(r\), and \(x\).

Output Format: For each query, output a single integer—the count of elements in the specified range \([l, r]\) that satisfy \(a_i \le x\).

inputFormat

The first line contains two space-separated integers \(n\) (the length of the sequence) and \(m\) (the number of queries).

The second line contains \(n\) space-separated integers \(a_1, a_2, \ldots, a_n\), representing the sequence.

Each of the next \(m\) lines contains three space-separated integers \(l\), \(r\), and \(x\), representing one query.

outputFormat

For each query, output the number of elements in the range \([l, r]\) that are less than or equal to \(x\). Each answer should be printed on a new line.

sample

5 3
1 2 3 4 5
1 3 3
2 5 4
1 5 5
3

3 5

</p>