1 #include<bits/stdc++.h> 2 using namespace std; 3 const int M = 1e5 + 10 ; 4 int n , m ; 5 pair<int , int> a[M] ; 6 int rk[M] ; 7 struct node { 8 int l , r , sum ; 9 } nd[M * 20] ; 10 int cnt = 0 ; 11 int rt[M] ; 12 13 void IN (int x , int &o , int l , int r) { 14 nd[cnt] = nd[o] ; 15 nd[cnt].sum ++ ; 16 o = cnt ++ ; 17 if (l == r) return ; 18 int mid = (l + r) >> 1 ; 19 if (x <= mid) IN (x , nd[o].l , l , mid ) ; 20 else IN (x , nd[o].r , mid + 1 , r) ; 21 } 22 23 int query (int o1 , int o2 , int k , int l , int r) { 24 if (l == r) return l ; 25 int t = nd[nd[o2].l].sum - nd[nd[o1].l].sum ; 26 printf ("t = %d " , t ) ; 27 int mid = (l + r) >> 1 ; 28 if (k <= t) return query (nd[o1].l , nd[o2].l , k , l , mid ) ; 29 else return query (nd[o1].r , nd[o2].r , k - t , mid + 1 , r ) ; 30 } 31 32 int main () { 33 while (~ scanf ("%d%d" , &n , &m) ) { 34 cnt = 0 ; 35 for (int i = 1 ; i <= n ; i ++) { 36 scanf ("%d" , &a[i].first ) ; 37 a[i].second = i ; 38 } 39 sort (a + 1 , a + n + 1) ; 40 for (int i = 1 ; i <= n ; i ++) rk[a[i].second] = i ; 41 for (int i = 1 ; i <= n ; i ++) { 42 rt[i] = rt[i - 1] ; 43 IN (rk[i] , rt[i] , 1 , n ) ; 44 } 45 while (m --) { 46 int l , r , k ; 47 scanf ("%d%d%d" , &l , &r , &k ) ; 48 printf ("%d " , a[query ( rt[l-1] , rt[r] , k , 1 , n )].first) ; 49 } 50 } 51 return 0 ; 52 }