#P10814. 【模板】离线二维数点

【模板】离线二维数点

Background

Frogs.

Problem Description

You are given a sequence aa of length nn. There are mm queries. Each query gives l,r,xl, r, x. Find the number of elements in the interval [l,r][l, r] that are less than or equal to xx.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers representing the sequence aa.

The following mm lines each contain three integers l,r,xl, r, x, representing one query.

Output Format

For each query, output one line with one integer, the answer.

6 4
1 1 4 5 1 4
1 6 3
1 6 4
1 1 4
1 5 4
3
5
1
4

Hint

For 20%20\% of the testdata, 1n,m,ai,l,r,x1001 \le n, m, a_i, l, r, x \le 100.

For 40%40\% of the testdata, 1n,m,ai,l,r,x1041 \le n, m, a_i, l, r, x \le 10^4.

For 60%60\% of the testdata, 1n,m,ai,l,r,x1051 \le n, m, a_i, l, r, x \le 10^5.

For 80%80\% of the testdata, 1n,m,ai,l,r,x1061 \le n, m, a_i, l, r, x \le 10^6.

For 100%100\% of the testdata, 1n,m,ai,l,r,x2×1061 \le n, m, a_i, l, r, x \le 2 \times 10^6.

Translated by ChatGPT 5