#C4346. Stock Prices Operations
Stock Prices Operations
Stock Prices Operations
In this problem, you are given the stock prices of companies and need to process operations. There are two types of operations:
-
Update Operation: Increase the stock price of a given company by a given amount. The operation is given in the format:
1 i x
, which means increase the price of the company at index (1-indexed) by . -
Query Operation: Report the maximum difference between stock prices in a specified range. The operation is given in the format:
2 l r
, which asks for the difference between the maximum and minimum stock prices among the companies from index to (inclusive).
Your task is to simulate these operations. For each query operation, compute the value $$\max_{i=l}^{r}(a_i) - \min_{i=l}^{r}(a_i),$$ where denotes the stock price of the -th company.
Input and output are to be handled through standard input and standard output.
inputFormat
The first line contains two integers and — the number of companies and the number of operations. The second line contains integers representing the initial stock prices. Each of the next lines contains an operation in one of the following two formats:
- Update operation:
1 i x
— increase the stock price of the -th company by . - Query operation:
2 l r
— output the maximum difference between any two stock prices in the range from to (inclusive).
outputFormat
For each query operation, output the result on a new line. There should be exactly one output per query.## sample
5 5
10 5 15 10 20
2 1 5
1 3 5
2 1 5
1 2 3
2 1 3
15
15
12
</p>