#include <iostream> #include <algorithm> #include <stdio.h> #include <string> #include <string.h> #include <stdlib.h> #include <math.h> #include <vector> #include <map> #include <queue> #include <stack> #include <set> using namespace std ; const int maxn = 100002; struct dog{ int value; int id; friend bool operator<(const dog &a,const dog &b){ return a.value<b.value; } }dog[maxn]; int has[maxn]; int dog_value[maxn]; struct feed{ int l,r,k; int id; friend bool operator<(const feed &a,const feed &b){ if(a.l == b.l) return a.r<b.r; return a.l<b.l; } }feed[maxn/2]; int n,m; int c[maxn]; int ans[maxn/2]; int lowbit(int x){ return x&(-x); } void update(int id,int val){ for(int i = id;i < maxn;i += lowbit(i)) c[i] += val; } int find_kth(int k){ int ans = 0,cnt = 0; for(int i = 20;i >= 0;i--){ ans += (1<<i); if(ans >= maxn || cnt + c[ans] >= k) ans -= (1<<i); else cnt += c[ans]; } return ans+1; } int main(){ while(~scanf("%d%d",&n,&m)){ for(int i = 1;i <= n;i++){ scanf("%d",&dog[i].value); dog[i].id = i; } sort(dog+1,dog+n+1); dog_value[1] = dog[1].value; has[dog[1].id] = 1; for(int i = 2,j = 1;i <= n;i++){ if(dog[i].value != dog[i-1].value) dog_value[++j] = dog[i].value; has[dog[i].id] = j; } //for(int i = 1;i <= n;i++) // printf("%d %d\n",has[i],dog_value[i]); for(int i = 1;i <= m;i++){ scanf("%d%d%d",&feed[i].l,&feed[i].r,&feed[i].k); feed[i].id = i; } sort(feed+1,feed+m+1); //for(int i = 1;i <= m;i++) // printf("%d %d %d\n",feed[i].l,feed[i].r,feed[i].k); feed[0].l=1;feed[0].r=0; for(int i=1;i<=m;i++){ for(int j=feed[i-1].l;j<=feed[i-1].r&&j<feed[i].l;j++) update(has[j],-1); for(int j=feed[i].l<feed[i-1].r+1?feed[i-1].r+1:feed[i].l;j<=feed[i].r;j++) update(has[j],1); int num=find_kth(feed[i].k); ans[feed[i].id]=dog_value[num]; } for(int i = 1;i <= m;i++) printf("%d\n",ans[i]); } return 0; }