History in Numbers
Time limit2sMemory limit1024 MB
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 years. Urban development is measured by an aggregate index called the urban development index (UDI), which takes integer values, including negative ones. Each year starts with an initial estimate of the UDI. As new documents and evidence are found, these estimates are revised. Historians may add to the UDI estimates of every year from to (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 3becomes1 2 3. - The UDI is considered increasing from year to year 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 (), the length of the time period.
The second line contains space-separated integers ().
The third line contains an integer (). Each of the next lines is one of the following requests:
updatefollowed by three integers , , and (, ).checkfollowed by two integers and ().
Output
For each check request, print YES if the UDI has been increasing over that period, and NO otherwise.