Under construction

Still being built. Things may change

Transmitter Towers

Time limit2sMemory limit1024 MB

Summary
For each query range [L, R] and value D, find the largest set of towers where every pair has a relay tower between them that is at least D taller.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy, Sorting
Solved
No attempts yet

Problem

Jakarta has NN transmitter towers. The towers lie on a straight line and are numbered from 00 to N−1N - 1 from left to right. For each ii with 0≤i≤N−10 \le i \le N - 1, the height of tower ii is H[i]H[i] meters. All tower heights are distinct.

For a positive interference value δ\delta, towers ii and jj (0≤i<j≤N−10 \le i < j \le N - 1) can communicate if there is a relay tower kk that satisfies both of the following conditions.

  • i<k<ji < k < j. That is, tower ii is to the left of tower kk, and tower jj is to the right of it.
  • The heights of towers ii and jj are each at most H[k]−δH[k] - \delta meters.

Pak Dengklek wants to rent some towers for her new transmission network. You must answer QQ queries. Each query gives parameters LL, RR, and DD (0≤L≤R≤N−10 \le L \le R \le N - 1, D>0D > 0), and asks for the maximum number of towers Pak Dengklek can rent. Assume the following:

  • She may rent only towers numbered from LL to RR, inclusive.
  • The interference value δ\delta is DD.
  • Every pair of towers she rents must be able to communicate.

When two rented towers communicate through a relay tower kk, tower kk may or may not be rented.

Constraints

  • 1≤N≤100 0001 \le N \le 100\,000
  • 1≤Q≤100 0001 \le Q \le 100\,000
  • 1≤H[i]≤1091 \le H[i] \le 10^9 (for all 0≤i≤N−10 \le i \le N - 1)
  • H[i]≠H[j]H[i] \ne H[j] (for all 0≤i<j≤N−10 \le i < j \le N - 1)
  • 0≤L≤R≤N−10 \le L \le R \le N - 1
  • 1≤D≤1091 \le D \le 10^9

Examples1

  1. Example 1

    Input
    1
    5
    1
    0 0 1
    
    Expected output
    1