#P3834. 【模板】可持久化线段树 2

    ID: 2791 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树离散化O2优化主席树可持久化

【模板】可持久化线段树 2

Description

As stated, given a sequence a a of n n integers, for each specified closed interval [l,r] [l, r] , query the k k -th smallest value within the interval.

Input Format

The first line contains two integers, the length n n of the sequence and the number m m of queries.
The second line contains n n integers; the i i -th integer is the i i -th element ai a_i of the sequence.
Each of the next m m lines contains three integers l,r,k l, r, k , denoting the k k -th smallest value within the range [l,r] [l, r] .

Output Format

For each query, output one line with a single integer, the answer.

5 5
25957 6405 15770 26287 26465 
2 2 1
3 4 1
4 5 1
1 2 2
4 4 1

6405
15770
26287
25957
26287

Hint

Sample 1 Explanation

n=5n=5, the sequence length is 55, and the sequence from the first term is {25957,6405,15770,26287,26465}\{25957, 6405, 15770, 26287, 26465\}.

  • The first query asks for the first smallest value in [2,2][2, 2], which is 64056405.
  • The second query asks for the first smallest value in [3,4][3, 4], which is 1577015770.
  • The third query asks for the first smallest value in [4,5][4, 5], which is 2628726287.
  • The fourth query asks for the second smallest value in [1,2][1, 2], which is 2595725957.
  • The fifth query asks for the first smallest value in [4,4][4, 4], which is 2628726287.

Constraints

  • For 10%10\% of the testdata, 1n,m101 \leq n,m \leq 10.
  • For 25%25\% of the testdata, 1n,m1031 \leq n,m \leq 10^3.
  • For 40%40\% of the testdata, 1n,m1051 \leq n,m \leq 10^5.
  • For 50%50\% of the testdata, 1n,m2×1051 \leq n,m \leq 2\times 10^5, 0ai2×1050\le a_i \leq 2\times 10^5.
  • For all testdata, 1n,m2×1051 \leq n,m \leq 2\times 10^5, 0ai1090\le a_i \leq 10^9, 1lrn1 \leq l \leq r \leq n, 1krl+11 \leq k \leq r - l + 1.

Translated by ChatGPT 5