func_code_string: #include <bits/stdc++.h>   using namespace std;   int N;   vector<int> fen, v;   void _update(int i) {     while (i <= N) {       fen[i]++;       i += i & -i;     }   }   int _sum(int i) {     int ret = 0;     while (i > 0) {       ret += fen[i];       i -= i & -i;     }     return ret;   }   int _bin(int i) {     int sum = _sum(i);     int imin = 1, imax = i;     while (imin <= imax) {       int imid = (imin + imax) / 2;       if (sum - _sum(imid - 1) >= v[i])         imin = imid + 1;       else         imax = imid - 1;     }     return imax;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int Q;     cin >> N >> Q;     v = vector<int>(N + 1);     for (int n = 1; n <= N; ++n) {       cin >> v[n];     }     for (int n = 1; n <= N; ++n) {       v[n] = n - v[n];     }     vector<int> answer(Q);     vector<vector<pair<int, int>>> _query(N + 1);     for (int q = 0; q < Q; ++q) {       int x, y;       cin >> x >> y;       _query[N - y].push_back({x + 1, q});     }     fen = vector<int>(N + 1);     for (int r = 1; r <= N; ++r) {       if (v[r] == 0) {         _update(r);       } else if (v[r] > 0) {         int tmp = _bin(r);         if (tmp) _update(tmp);       }       for (auto x : _query[r]) {         answer[x.second] = _sum(r) - _sum(x.first - 1);       }     }     for (auto x : answer) cout << x <<   n ;     return 0;   }   