Point Coverage

5

1 votes
Segment tree, Advanced Data Structures, Segment Trees, Data Structures
Problem

There are N points located on the X axis at positions A1,A2,,AN respectively. Alice performs (N1) journeys. During the ith journey (1iN1), Alice moves from ith point to (i+1)th point (i.e from position Ai to position Ai+1).

You have to answer Q queries of the following form:

  • Li,Ri,Xi(1LiRiN1): How many times does Alice go over point Xi during Lthi to Rthijourney?

 Input format

  • The first line of input contains N denoting the number of points on X-axis and Q denoting the number of queries.
  • The second line contains N integers A1,A2,,AN denoting the positions of the points on the X axis.
  • Q lines follow. The ith of these lines contains three integers Li,Ri,Xi.

Output format
For each query, print the answer in a separate line.

Constraints

2N,Q21051Ai,Xi109AiAi+11LiRiN1XiAj(1iQ,1jN)

Sample Input
6 4
1 10 8 4 12 17
1 3 5
2 4 11
3 5 7
1 5 9




Sample Output
2
1
2
3
Time Limit: 1.5
Memory Limit: 256
Source Limit:
Explanation

Query 1: During the 1st journey and 3rd journey Alice goes over point 5.

Query 2: During the 4th Alice goes over point 11.

Query 3: During the 3rd and 4th journey Alice goes over point 7.

Query 4: During the 1st, 2nd, and 4th journey Alice goes over point 9.

Editor Image

?