PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000227. Thứ hạng động trong đoạn (Dynamic Rankings)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Thứ hạng động trong đoạn (Dynamic Rankings)

Dynamic Rankings

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array aa of nn integers, indexed from 11 through nn. Its entries may change over time.

Process mm operations in order:

  • Q l r k: Take the elements al,al+1,…,ara_l,a_{l+1},\ldots,a_r, sort these entries into nondecreasing order, and output the value occupying position kk in the sorted list. Equal values count as separate occurrences.
  • C x y: Set the element at position xx to yy. All subsequent queries must use the updated array.

A query always refers to a contiguous, inclusive interval [l,r][l,r] of the current array.

Input

  • The first line contains integers n,mn,m, the array length and the number of operations.
  • The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.
  • Each of the following mm lines is either Q l r k or C x y. Positions l,r,xl,r,x are 11-based.

Output

For every Q operation, output the kk-th smallest value (counting duplicates) in the current interval [l,r][l,r], one per line. A C operation produces no output.

Subtasks

  • Subtask 1 (20 points): 1≤n≤501\le n\le 50; 1≤m≤801\le m\le 80; 0≤ai≤1090\le a_i\le10^9 for every ii; for Q: 1≤l≤r≤n1\le l\le r\le n and 1≤k≤r−l+11\le k\le r-l+1; for C: 1≤x≤n1\le x\le n and 0≤y≤1090\le y\le10^9.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤m≤40001\le m\le 4000; 0≤ai≤1090\le a_i\le10^9 for every ii; for Q: 1≤l≤r≤n1\le l\le r\le n and 1≤k≤r−l+11\le k\le r-l+1; for C: 1≤x≤n1\le x\le n and 0≤y≤1090\le y\le10^9.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤m≤1000001\le m\le 100000; 0≤ai≤1090\le a_i\le10^9 for every ii; for Q: 1≤l≤r≤n1\le l\le r\le n and 1≤k≤r−l+11\le k\le r-l+1; for C: 1≤x≤n1\le x\le n and 0≤y≤1090\le y\le10^9.

Examples

Input

6 7
4 1 4 2 3 2
Q 1 6 3
C 2 5
Q 2 5 2
C 6 0
Q 1 6 1
Q 3 4 2
Q 1 6 6

Output

2
3
0
4
5

Explanation

Initially the array is [4,1,4,2,3,2][4,1,4,2,3,2].

  • Q 1 6 3: Sorting the six entries gives [1,2,2,3,4,4][1,2,2,3,4,4]; the third value is 22.
  • C 2 5: The array becomes [4,5,4,2,3,2][4,5,4,2,3,2].
  • Q 2 5 2: Sorting the queried subarray [5,4,2,3][5,4,2,3] gives [2,3,4,5][2,3,4,5], so the second value is 33.
  • C 6 0: The array becomes [4,5,4,2,3,0][4,5,4,2,3,0].
  • Q 1 6 1: The smallest value in the array is now 00.
  • Q 3 4 2: The segment [4,2][4,2] sorts into [2,4][2,4], so the answer is 44.
  • Q 1 6 6: Sorting the full array gives [0,2,3,4,4,5][0,2,3,4,4,5], whose sixth value is 55.

Therefore the program outputs 2, 3, 0, 4, 5 in this order.