P4314 CPU Monitoring

Background

Bob's machine is terrible... really terrible... to the point that when watching videos or running evil brute-force programs, it crashes due to sustained high CPU usage.

Description

Bob needs a program to monitor CPU usage. This is a tedious task. To make it simpler, Bob will gradually list what he will do today while using the computer. Bob does many things. Besides running brute-force programs and watching videos, he also goes out to play, randomly clicks the mouse, and might even kick out the power cord. Some actions increase or decrease the CPU usage by a value during the time they are performed; some actions directly set the CPU usage to a specific value. Of course, Bob will ask: under the influence of the previously listed events, what is the maximum CPU usage in a certain time interval. Sometimes Bob will also curiously ask: in a certain time interval, what is the highest CPU usage that has ever been reached. To be precise, usage is represented by an integer instead of a percentage. It is not guaranteed that Bob's event list is free of weird issues that could make the usage negative... # Description

Input Format

The first line contains a positive integer $T$, the total time Bob needs to monitor the CPU. The second line contains $T$ numbers indicating, before your monitoring program starts, the CPU usage that has already been reached at each moment within this time span. The third line contains an integer $E$, the total number of actions and queries Bob will perform. Each of the next $E$ lines is either a query or an event: - `Q X Y`: Query the maximum current CPU usage from $X$ to $Y$ (under the effects of all events listed so far). - `A X Y`: Query the highest CPU usage that has ever been reached from $X$ to $Y$ (over the entire history up to now). - `P X Y Z`: List an event that increases the CPU usage by $Z$ from $X$ to $Y$. - `C X Y Z`: List an event that sets the CPU usage to $Z$ from $X$ to $Y$. Time is measured in seconds, and usage has no unit. $X$ and $Y$ are positive integers ($X\le Y$), and $Z$ is an integer. The interval from $X$ to $Y$ is inclusive of second $X$ and second $Y$. It is guaranteed that all necessary operations fit within 32-bit signed integers.

Output Format

For each query, output one integer on its own line as the answer.

Explanation/Hint

The testdata is distributed as follows: - In testdata 1 and 2, $T$ and $E$ are both at most $10^3$. - In testdata 3 and 4, there are only `Q` queries. - In testdata 5 and 6, there are only `C` events. - In testdata 7 and 8, there are only `P` events. For $100\%$ of the testdata, $1\le T,E\le 10^5$, $1\le X\le Y\le T$, $-2^{31}\leq Z\lt 2^{31}$. Translated by ChatGPT 5