Task
SD is one of the subjects taught in the first semester at UAIC-FII.
During the first seminar of this subject, the professor introduced the classic problem "Maximum Subarray Sum" to group 1A1. Naturally, everyone proposed different solutions, but two students found it interesting to present the following problem for you to solve:
We define a circular array as an array where the last element is considered adjacent to the first, allowing continuous traversal without a defined endpoint.
Given an array with elements, indexed from to , and operations of two types:
- Update: For an index and a number , the number at position is updated to .
- Query: For two indices and , considering the subarray of between indices and as a circular array, determine the maximum sum of any non-empty subarray in that subarray.
Input data
The first line contains the numbers and .
The second line contains the numbers of array .
The next lines describe the operations as follows:
Each line contains three numbers:
- The first number is either or , depending on the type of operation.
- If the first number is , the operation is an update, followed by numbers and as described in the statement.
- If the first number is , the operation is a query, followed by numbers and as described in the statement.
The values on the same line are space separated.
Output data
The output contains the maximum sums determined for each query operation, in the order given in the input, each on a separate line.
Constraints and clarifications
# | Score | Restrictions |
---|---|---|
1 | 15 | |
2 | 20 | |
3 | 20 | Only query operations exist in the input. |
4 | 20 | |
5 | 25 | No additional restrictions. |
Example
stdin
12 7
1 -5 2 3 4 -2 5 6 11 -1 15 -2
2 12 12
1 4 5
2 1 5
2 3 8
1 6 2
2 3 8
2 9 12
stdout
-2
12
22
24
25