Under construction

Still being built. Things may change

Flooding

Interview

Time limit2sMemory limit1024 MB

Summary
Given heights and queries (l, r, x), count the maximal runs of heights strictly above x that lie within positions l to r.
Level

Medium5 of 10

Topics
Array, Sorting, Prefix sum
Solved
No attempts yet

Problem

It is winter, and it has never been colder. Mr. Malnar looks at his photos from his last cruise on the Adriatic and remembers unforgettable moments. On the TV in the background, the news reports the latest proposals for slowing sea level rise. Looking at his coastal photos, Mr. Malnar wonders what they would have looked like if the sea had risen by a certain amount. There are so many pictures and so many questions that he asks for your help.

We model the coast as a sequence of nn numbers h1,h2,…,hnh_1, h_2, \dots, h_n, where hih_i is the relief height at the ii-th point. Mr. Malnar has qq queries. The ii-th query asks: if the sea level rose by xix_i meters, how many islands would there be between the lil_i-th and rir_i-th points?

An island is a maximal interval in which every hih_i is strictly greater than the sea level. A maximal interval cannot be extended in either direction while keeping that condition. The sea level starts at 00 meters.

Input

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

The second line contains nn integers h1,h2,…,hnh_1, h_2, \dots, h_n (0≤hi≤1090 \le h_i \le 10^9) that describe the relief of the coast.

Each of the next qq lines contains three integers lil_i, rir_i and xix_i (1≤li≤ri≤n1 \le l_i \le r_i \le n, 0≤xi≤1090 \le x_i \le 10^9) that describe the ii-th query.

Output

Print qq lines. The ii-th line contains the answer to the ii-th query.

Hint

In the first query of the first sample, the islands are the intervals [2,2][2, 2] and [4,5][4, 5] (left image). The second query has one island, [5,5][5, 5]. The third query has no islands because everything is under water.

In the second sample, the first query has islands [3,5][3, 5] and [8,9][8, 9]. The second query (right image) has islands [1,1][1, 1], [4,4][4, 4], [8,8][8, 8] and [10,10][10, 10]. The third query has islands [1,1][1, 1], [3,4][3, 4] and [8,10][8, 10].

Examples2

  1. Example 1

    Input
    6 3
    2 4 2 3 4 1
    2 5 2
    3 5 3
    3 4 4
    
    Expected output
    2
    1
    0
    
  2. Example 2

    Input
    10 3
    5 0 3 4 2 0 1 6 3 5
    3 9 1
    1 10 3
    1 10 2
    
    Expected output
    2
    4
    3