func_code_string: #include <bits/stdc++.h>   using namespace std;   int const sqN = 320;   int add(int a, int b);   int sub(int a, int b);   int arr[100005];   struct query {     int index;     int l;     int r;     int ans;   };   bool comp(query &a, query &b) {     if (a.l / sqN != b.l / sqN) {       return a.l / sqN < b.l / sqN;     }     return a.r < b.r;   }   bool comp_by_index(query &a, query &b) { return a.index < b.index; }   int main() {     int n, m, aux, l, r, cnt;     cin >> n >> m;     vector<int> F;     F.push_back(0);     for (int i = 0; i < n; i++) {       cin >> aux;       if (aux > 100000) aux = 0;       F.push_back(aux);     }     vector<query> Q;     for (int i = 0; i < m; i++) {       cin >> l >> r;       query inp;       inp.index = i;       inp.l = l;       inp.r = r;       Q.push_back(inp);     }     sort(Q.begin(), Q.end(), comp);     memset(arr, 0, sizeof(arr));     r = 1;     l = 0;     cnt = (F[1] == 1) ? 1 : 0;     arr[F[1]] += 1;     for (int i = 0; i < m; i++) {       query curq = Q[i];       while (r < Q[i].r) {         r++;         cnt += sub(arr[F[r]], F[r]);         arr[F[r]] += 1;         cnt += add(arr[F[r]], F[r]);       }       while (l < Q[i].l - 1) {         l++;         cnt += sub(arr[F[l]], F[l]);         arr[F[l]] -= 1;         cnt += add(arr[F[l]], F[l]);       }       while (l >= Q[i].l) {         cnt += sub(arr[F[l]], F[l]);         arr[F[l]] += 1;         cnt += add(arr[F[l]], F[l]);         l--;       }       while (r > Q[i].r) {         cnt += sub(arr[F[r]], F[r]);         arr[F[r]] -= 1;         cnt += add(arr[F[r]], F[r]);         r--;       }       Q[i].ans = cnt;     }     sort(Q.begin(), Q.end(), comp_by_index);     for (int i = 0; i < Q.size(); i++) cout << Q[i].ans << endl;   }   int add(int a, int b) {     if (b > 0 and b == a) return 1;     return 0;   }   int sub(int a, int b) {     if (b > 0 and b == a) return -1;     return 0;   }   