SD

Time limit: 1.5s Memory limit: 256MB Input: Output:

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 AA with NN elements, indexed from 11 to NN, and QQ operations of two types:

  • Update: For an index ii (1iN)(1 \leq i \leq N) and a number XX, the number at position ii is updated to XX (Ai=X)(A_i=X).
  • Query: For two indices StSt and DrDr (1StDrN)(1 \leq St \leq Dr \leq N), considering the subarray of AA between indices StSt and DrDr as a circular array, determine the maximum sum of any non-empty subarray in that subarray.

Input data

The first line contains the numbers NN and QQ.

The second line contains the NN numbers of array AA.

The next QQ lines describe the operations as follows:

Each line contains three numbers:

  • The first number is either 11 or 22, depending on the type of operation.
  • If the first number is 11, the operation is an update, followed by numbers ii and XX as described in the statement.
  • If the first number is 22, the operation is a query, followed by numbers StSt and DrDr 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

  • 1N,Q300 0001 \leq N, Q \leq 300 \ 000
  • 1i,St,DrN1 \leq i, St, Dr \leq N
  • 109Ai,X109,(1iN)-10^9\leq A_i, X\leq 10^9, (1 \leq i \leq N)
# Score Restrictions
1 15 1N,Q5001 \leq N, Q \leq 500
2 20 500<N,Q2000500 < N, Q \leq 2000
3 20 Only query operations exist in the input.
4 20 St=1,Dr=NSt=1, Dr=N
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

Log in or sign up to be able to send submissions!