Segment Tree Practice 3

View as PDF

Submit solution

Points: 15
Time limit: 0.6s
Java 5.0s
Memory limit: 256M

Author:
Problem type

Given an array A of size N, support the Q of the following operations:

  1. Find the maximum prefix sum of the subarray from index l to index r. That is, find the maximum sum of a subarray starting at l and ending in the range [l,r].
  2. Update the element at index i to value x.

Constraints

1N,Q2×105

1lrN

1iN

109Ai,x109

Input Specification

The first line contains 2 integers N and Q.

The second line contains N integers A1,A2,,AN, the initial elements of A.

The next Q lines are one of two forms:

  1. P l r representing the first operation.
  2. U i x representing the second operation.

Output Specification

For each type 1 operation output one integer on its own line, the answer to that query.

Sample Input

Copy
7 5
-1 3 2 -6 5 -6 7
P 2 6
P 5 7
U 4 -3
P 2 6
P 1 1

Sample Output

Copy
5
6
7
-1

Comments

There are no comments at the moment.