func_code_string: #include <bits/stdc++.h>   using namespace std;   map<int, int> cnt;   int n;   int m;   int dp[500][100005];   vector<int> num;   map<int, int> can;   int ind = 0;   int dpnum[500];   map<int, int> mpind;   map<int, int> mpvis;   int main() {     scanf( %d%d , &n, &m);     int x;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       num.push_back(x);       if (can[x] == 0) {         if (cnt[x] < x) {           cnt[x]++;         }         if (cnt[x] == x) {           can[x] = 1;         }       }     }     for (int i = 0; i < n; i++) {       if (!can[num[i]]) continue;       if (mpind[num[i]] != 0) continue;       if (mpind[num[i]] == 0) {         ind++;         mpind[num[i]] = ind;         dpnum[ind] = num[i];       }       int tind = mpind[num[i]];       for (int j = 0; j < n; j++) {         if (j == 0) {           if (num[j] == num[i])             dp[tind][j + 1] = 1;           else             dp[tind][j + 1] = 0;         } else {           if (num[j] == num[i])             dp[tind][j + 1] = dp[tind][j] + 1;           else             dp[tind][j + 1] = dp[tind][j];         }       }     }     int l, r;     for (int i = 0; i < m; i++) {       scanf( %d%d , &l, &r);       int ans = 0;       for (int i = 1; i <= ind; i++) {         if (dp[i][r] - dp[i][l - 1] == dpnum[i]) {           ans++;         }       }       printf( %d n , ans);     }     return 0;   }   