func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   struct query {     long long k, pos, ind;   };   struct fenwick {     long long n;     vector<long long> f;     fenwick(long long _n) {       n = _n;       f.resize(n, 0);     }     void add(long long val, long long i) {       for (; i < n; i |= (i + 1)) f[i] += val;     }     long long sum(long long i) {       long long ans = 0;       for (; i >= 0; i &= (i + 1), --i) ans += f[i];       return ans;     }   };   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<pair<long long, long long> > a(n);     vector<long long> start(n);     for (long long i = 0; i < n; ++i) {       cin >> a[i].first;       start[i] = a[i].first;       a[i].second = i;     }     sort(a.begin(), a.end(),          [](pair<long long, long long> a, pair<long long, long long> b) {            if (a.first == b.first) return a.second > b.second;            return a.first < b.first;          });     reverse(a.begin(), a.end());     long long q;     cin >> q;     vector<query> qs(q);     for (long long t = 0; t < q; ++t) {       cin >> qs[t].k >> qs[t].pos;       qs[t].k--;       qs[t].pos--;       qs[t].ind = t;     }     sort(qs.begin(), qs.end(), [](query a, query b) { return a.k < b.k; });     fenwick f(n);     long long l = -1;     vector<long long> ans(q);     for (long long i = 0; i < q; ++i) {       while (l < qs[i].k) {         ++l;         f.add(1, a[l].second);       }       long long L = 0, R = n - 1;       while (R - L > 1) {         long long m = (R + L) / 2;         if (f.sum(m) <= qs[i].pos) {           L = m;         } else           R = m;       }       if (f.sum(L) < qs[i].pos + 1) swap(L, R);       ans[qs[i].ind] = start[L];     }     for (auto x : ans) cout << x <<   n ;   }   