시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB35212064.516%

문제

Vini is a very dedicated car painter. Ever since he learned how to paint cars, his dream was to participate in the International Competition for Painting Cars (ICPC for short).

Every year Vini’s region has a local competition to rank all teams of competitive car painters from this region. Painters in teams that were ranked in the top x spots will then go on to compete in the ICPC. It is a very thrilling competition with lots of new competitors every year, until the noxious fumes from the car paint eventually leads them to permanently retire.

Because of the variance in the national car painting budget and ICPC constraints, this number x may vary between years, which may cause a lot of displeasure in some competitors.

On Vini’s last year as a contestant, his team was a single position away from qualifying to the ICPC. How unlucky! To make his “bad luck” feeling worse, in the following year the team who got the same position did qualify! Despite this feeling, after talking to other former contestants, he noticed that many have had the same feeling of being unlucky in one way or another.

Former contestants usually follow the results of the regional competition for a few years after retiring. Hence, a contestant would not feel unlucky for changes in x that occur many years after they retire. More precisely, each former contestant had their last participation in the year ai, being placed in the position pi and, after retiring, followed results for the next fi years.

A contestant that didn’t qualify to the ICPC in their last participation has felt unlucky on every year that they followed the results in which they would qualify to the ICPC if they had competed in that year. In other words, for every year up to fi years after the contestant retired, if they didn’t qualify in their last participation, they felt unlucky if the number of teams that qualify for the ICPC in this year was at least pi.

Given the number of slots per year and the information about the former contestants, we want to know how many years each former contestant felt unlucky.

입력

The first line contains two integers Y and N (1 ≤ Y, N ≤ 3 × 105), representing the number of years of competition and the number of former contestants that Vini had talked to, respectively. (Yes, painting cars is a millenary tradition, also a very popular one!).

The next line contains Y integers x1, x2, . . . , xY (0 ≤ xi ≤ 105), representing the how many slots to the ICPC for their region there were for each year.

Each of the next N lines contains three integers ai, pi and fi (1 ≤ ai ≤ Y, 1 ≤ pi ≤ 105, 0 ≤ fi ≤ Y − ai), representing the year that the i-th former competitor had their last participation, the position the i-th former competitor’s team ranked and for how many years after competing the i-th former competitor followed the results after retiring, respectively.

출력

Output N lines, the i-th line should contain how many years the i-th former competitor felt unlucky.

예제 입력 1

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

예제 출력 1

3
0
1

예제 입력 2

4 1
8 8 8 8
1 7 3

예제 출력 2

0