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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 of integers, indexed from through . Its entries may change over time.
Process operations in order:
Q l r k: Take the elements , sort these entries into nondecreasing order, and output the value occupying position in the sorted list. Equal values count as separate occurrences.C x y: Set the element at position to . All subsequent queries must use the updated array.
A query always refers to a contiguous, inclusive interval of the current array.
Input
- The first line contains integers , the array length and the number of operations.
- The second line contains exactly integers .
- Each of the following lines is either
Q l r korC x y. Positions are -based.
Output
For every Q operation, output the -th smallest value (counting duplicates) in the current interval , one per line. A C operation produces no output.
Subtasks
- Subtask 1 (20 points): ; ; for every ; for
Q: and ; forC: and . - Subtask 2 (30 points): ; ; for every ; for
Q: and ; forC: and . - Subtask 3 (50 points): ; ; for every ; for
Q: and ; forC: and .
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 .
Q 1 6 3: Sorting the six entries gives ; the third value is .C 2 5: The array becomes .Q 2 5 2: Sorting the queried subarray gives , so the second value is .C 6 0: The array becomes .Q 1 6 1: The smallest value in the array is now .Q 3 4 2: The segment sorts into , so the answer is .Q 1 6 6: Sorting the full array gives , whose sixth value is .
Therefore the program outputs 2, 3, 0, 4, 5 in this order.