oiasufonsoif
turing_lisihan
2023-10-21 12:01:31
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
int n, q, l, r, k;
int a[maxn], b[maxn];
int kth(int l, int r, int k) {
if (l == r) return a[l];
int s = l, t = r;
int pos = rand() % (r - l + 1) + l;
swap(a[l], a[pos]);
int p=a[l];
while (s<t) {
while (s<t&&a[t]>p) t--;
if (s<t) a[s++] = a[t];
while (s<t&&a[s]<p) s++;
if (s<t) a[t--]=a[s];
}
a[s]=p;
if (k<=s-1) return kth(l, s-1, k);
else if (k>=t+1) return kth(t+1, r, k);
return a[s];
}
int main() {
cin >> n;
for (int i=1;i<=n;i++) {
cin >> b[i];
}
cin >> q;
for (int i=1;i<=q;i++) {
cin >> l >> r >> k;
for (int j=1, k=l;k<=r;j++, k++) {
a[j]=b[k];
}
cout << kth(1, r-l+1, k) << endl;
}
return 0;
}