Segment Tree Practice 2

View as PDF

Submit solution

Points: 12
Time limit: 0.6s
Memory limit: 256M

Author:
Problem type

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

  1. Find the value and index of the smallest element from index l to index r. If there are multiple smallest elements, find the index of the earliest one.
  2. Update the element at index i to value x.

Constraints

1N,Q2×105

1lrN

1iN

1Ai,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. M l r representing the first operation.
  2. U i x representing the second operation.

Output Specification

For each type 1 operation output two integers, the minimum value and the leftmost index of that value in the given range.

Sample Input

Copy
5 5
6 3 3 2 4
M 2 4
M 2 3
U 2 6
M 1 2
M 1 3

Sample Output

Copy
2 4
3 2
6 1
3 3

Comments

There are no comments at the moment.