#P2617. Dynamic Rankings

Dynamic Rankings

Description

Given a sequence of nn numbers a1,a2ana_1,a_2 \dots a_n, you need to support two operations:

  • Q l r k queries the kk-th smallest number among indices in the interval [l,r][l,r].
  • C x y sets axa_x to yy.

Input Format

The first line contains two positive integers n,mn,m, the sequence length and the number of operations. The second line contains nn integers, representing a1,a2ana_1,a_2 \dots a_n. The next mm lines each describe an operation, which is one of the two types above.

Output Format

For each query, output one integer on a separate line representing the answer.

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

Hint

Constraints:

  • For 10%10\% of the testdata, 1n,m1001 \le n,m \le 100.
  • For 20%20\% of the testdata, 1n,m10001 \le n,m \le 1000.
  • For 50%50\% of the testdata, 1n,m1041 \le n,m \le 10^4.
  • For 100%100\% of the testdata, 1n,m1051 \le n,m \le 10^5, 1lrn1 \le l \le r \le n, 1krl+11 \le k \le r-l+1, 1xn1 \le x \le n, 0ai,y1090 \le a_i,y \le 10^9.

Pay attention to constant-factor optimizations, but straightforward implementations of overall binary search on values ("整体二分") and tree-of-trees ("树套树") can both pass in about 1000 ms per test point.

Source: bzoj1901.

This problem uses custom Luogu testdata, generated with CYaRon in 55 minutes.

Translated by ChatGPT 5