颓简单板子
随便打一次
就不口胡了
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<map>
using namespace std;
#define getchar() (frS==frT&&(frT=(frS=frBB)+fread(frBB,1,1<<12,stdin),frS==frT)?EOF:*frS++)
char frBB[1<<12],*frS=frBB,*frT=frBB;
int read()
{
int x = 0; bool w = 0; char ch = getchar();
while (!isdigit(ch)) w |= (ch == '-'), ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
return w?-x:x;
}
const int MAXN = 200005;
const int MAXS = 22 * MAXN;
int n, m, tot = 0, a[MAXN], tmp[MAXN], Seg[MAXS], LC[MAXS], RC[MAXS], Rt[MAXN], Cord[MAXN];
void Build(int &cur, int L, int R)
{
cur = ++tot;
if(L == R) return;
int Mid = L + R >> 1;
Build(LC[cur], L, Mid);
Build(RC[cur], Mid + 1, R);
}
void Insert(int &cur, int pre, int L, int R, int val)
{
cur = ++tot;
Seg[cur] = Seg[pre] + 1, LC[cur] = LC[pre], RC[cur] = RC[pre];
if (L == R) return;
int Mid = L + R >> 1;
if (val <= Mid) Insert(LC[cur], LC[pre], L, Mid, val);
else Insert(RC[cur], RC[pre], Mid + 1, R, val);
}
int Query(int cur, int pre, int L, int R, int kth)
{
if (L == R) return Cord[L];
int Mid = L + R >> 1;
if (Seg[LC[cur]] - Seg[LC[pre]] >= kth) return Query(LC[cur], LC[pre], L, Mid, kth);
else return Query(RC[cur], RC[pre], Mid + 1, R, kth - Seg[LC[cur]] + Seg[LC[pre]]);
}
int main()
{
n = read(); m = read();
for (int i = 1; i <= n; ++i)
{
a[i] = read();
tmp[i] = a[i];
}
tmp[0] = unique(tmp + 1, tmp + 1 + n) - tmp;
sort(tmp + 1, tmp + 1 + tmp[0]);
for (int tt, i = 1; i <= n; ++i)
{
tt = a[i];
a[i] = lower_bound(tmp + 1, tmp + 1 + tmp[0], a[i]) - tmp;
Cord[a[i]] = tt;
}
Build(Rt[0], 1, tmp[0]);
for (int i = 1; i <= n; ++i) Insert(Rt[i], Rt[i-1], 1, tmp[0], a[i]);
for (int l, r, k, i = 1; i <= m; ++i)
{
l = read(); r = read(); k = read();
printf("%d\n", Query(Rt[r], Rt[l-1], 1, tmp[0], k));
}
return 0;
}