Under construction

Still being built. Things may change

History in Numbers

Time limit2sMemory limit1024 MB

Summary
Given n yearly estimates with range-add updates, decide for each query range whether the local minima of its run-compressed sequence are strictly increasing.
Level

Medium7 of 10

Topics
Segment tree, Array, Implementation
Solved
No attempts yet

Problem

Algorithms and data structures find their place in various arts, crafts, and sciences. This problem covers one application in history.

Historians study the urban development of a city over a period of nn years. Urban development is measured by an aggregate index called the urban development index (UDI), which takes integer values, including negative ones. Each year ii starts with an initial estimate eie_i of the UDI. As new documents and evidence are found, these estimates are revised. Historians may add djd_j to the UDI estimates of every year from sjs_j to fjf_j (inclusive).

Historians want to know whether the UDI has been increasing over a period. They use the following procedure instead of the standard definition:

  • Collapse every run of consecutive equal numbers into one. For example, 1 1 2 2 2 3 3 3 becomes 1 2 3.
  • The UDI is considered increasing from year ii to year jj if the sequence of local minima in the transformed UDI sequence is strictly increasing. An element is a local minimum if it is less than both of its neighbors (one neighbor for the first or last element).

Implement a system that stores the UDI estimates and processes update and check requests.

Input

The first line contains an integer nn (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5), the length of the time period.

The second line contains nn space-separated integers eie_i (−108≤ei≤108-10^8 \le e_i \le 10^8).

The third line contains an integer mm (1≤m≤3⋅1051 \le m \le 3 \cdot 10^5). Each of the next mm lines is one of the following requests:

  • update followed by three integers sjs_j, fjf_j, and djd_j (1≤sj≤fj≤n1 \le s_j \le f_j \le n, ∣dj∣≤108|d_j| \le 10^8).
  • check followed by two integers ss and ff (1≤s≤f≤n1 \le s \le f \le n).

Output

For each check request, print YES if the UDI has been increasing over that period, and NO otherwise.

Examples2

  1. Example 1

    Input
    5
    10 4 10 6 10
    5
    check 1 5
    update 2 3 1
    check 1 5
    update 2 3 1
    check 1 5
    
    Expected output
    YES
    YES
    NO
    
  2. Example 2

    Input
    8
    10 -5 -5 -5 11 6 6 12
    1
    check 1 8
    
    Expected output
    YES