아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Zatopljenje

시간 제한2초메모리 제한1024 MB

요약
높이 배열과 질의 (l, r, x)가 주어질 때, 구간 [l, r] 안에서 해수면 x보다 높은 극대 구간의 개수를 센다.
난이도

보통10점 중 7점

유형
배열, 정렬, 누적 합, 이분 탐색
정답자
아직 제출이 없습니다

문제

It’s winter, it has never been colder, and Mr. Malnar is looking at his photos from his last cruise on the Adriatic and recalls unforgettable moments. The TV is on in the background, broadcasting news about the latest proposals for measures to slow down sea level rise. Looking at his photos of the coast, Mr. Malnar asks himself what the photos would have looked like if sea level had risen a certain amount. There are so many pictures, and even more questions, so Mr. Malnar asks for your help.

We imagine the coast as a sequence of nn numbers h_1,h_2,…,h_nh\_1, h\_2, \dots , h\_n, where the ii-th number represents relief height at the ii-th point. Mr. Malnar has qq queries, where the ii-th query is as following: How many islands would there be between the l_il\_i-th and r_ir\_i-th point if the sea level rose by x_ix\_i meters?

The left image shows the first query of the first sample test case, and the right image shows the second query of the second sample test case.

The left islands correspond to intervals \[2,2]\[2, 2] and \[4,5]\[4, 5].

The right islands correspond to intervals \[1,1]\[1, 1], \[4,4]\[4, 4], \[8,8]\[8, 8] and \[10,10]\[10, 10].

An island is defined as the maximal interval where every h_ih\_i is strictly greater than the sea level. A maximal interval is one that cannot be extended in either direction while keeping the mentioned condition true. Initially, the sea level is at 00 meters.

입력

The first line contains integers nn and qq (1≤n,q≤2⋅1051 ≤ n, q ≤ 2 \cdot 10^5), the length of the sequence and the number of queries.

The second line contains nn integers h_1,h_2,…,h_nh\_1, h\_2, \dots , h\_n (0≤h_i≤1090 ≤ h\_i ≤ 10^9) that describe the relief of the coast.

In each of the next qq lines there are three integers l_il\_i, r_ir\_i and x_ix\_i (1≤l_i≤r_i≤n1 ≤ l\_i ≤ r\_i ≤ n, 0≤x_i≤1090 ≤ x\_i ≤ 10^9) that describe the ii-th query.

출력

In the ii-th of the qq lines print the answer to the ii-th query. Each of the queries is independent of the others.

힌트

Clarification of the first example:

The first query is shown in the left image in the task description, islands correspond to intervals \[2,2]\[2, 2] and \[4,5]\[4, 5]. In the second query island corresponds to interval \[5,5]\[5, 5]. In the third query there are no islands because everything is under water.

Clarification of the second example: In the first query islands correspond to intervals \[3,5]\[3, 5] and \[8,9]\[8, 9]. In the second query (shown in the right image in the task description) islands correspond to intervals \[1,1]\[1, 1], \[4,4]\[4, 4], \[8,8]\[8, 8] and \[10,10]\[10, 10], while in the third query islands correspond to intervals \[1,1]\[1, 1], \[3,4]\[3, 4] and \[8,10]\[8, 10].

예제2

  1. 예제 1

    입력
    6 3
    2 4 2 3 4 1
    2 5 2
    3 5 3
    3 4 4
    
    예상 출력
    2
    1
    0
    
  2. 예제 2

    입력
    10 3
    5 0 3 4 2 0 1 6 3 5
    3 9 1
    1 10 3
    1 10 2
    
    예상 출력
    2
    4
    3