Problems > Leftmost Big Enough

Leftmost Big Enough

Difficulty: 1900 4000 ms 128 MB

segment-tree

Support U i v (assign ai = v) and Q x — print the SMALLEST index whose value is ≥ x, or −1.

Input: the first line has N and Q; the second line has the array; each of the next Q lines is an operation.

Output: one line per query.

Constraints:

  • 1 ≤ N, Q ≤ 105
  • |values|, |x| ≤ 106

Sample Tests

Input 1
5 3
3 1 4 1 5
Q 4
U 3 0
Q 4
Output 1
3
5
Input 2
1 1
5
Q 6
Output 2
-1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.