#include <bits/stdc++.h>
using namespace std;
const int K=450,maxn=1<<20;
int freq[maxn+1];
struct Mos {
    int k;
    int id;
    int cur;
    Mos(){}
    void add(int x) {
        if(x>=maxn) return;
        if(freq[x]==x)cur--;
        freq[x]++;
        if(freq[x]==x)cur++;
        // cout<<cur<<" "<<x<<" "<<freq[x]<<endl;
    }
    void remove(int x) {
        if(x>=maxn) return;
        if(freq[x]==x)cur--;
        freq[x]--;
        if(freq[x]==x)cur++;
    }
    void process(vector<int>& a, vector<array<int,3>>& qs) {
        auto cmp = [&](array<int,3> &a, array<int,3> &b){return make_pair(make_pair(a[0]/K,a[1]/K),a) < make_pair(make_pair(b[0]/K,b[1]/K),b);};
        sort(qs.begin(),qs.end(),cmp);

        vector<int> ans(qs.size());
        cur=0;
        int l = 0;
        int r = -1;
        for (auto& [xl,xr,xid] : qs) {
            while (l > xl) add(a[--l]);
            while (r < xr) add(a[++r]);
            while (l < xl) remove(a[l++]);
            while (r > xr) remove(a[r--]);
            ans[xid] = cur;
        }
        for(auto i:ans)cout<<i<<endl;
    }
};
int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n,q,c;cin>>n>>q>>c;
    vector<int> a(n);for(int&i:a)cin>>i;
    vector<array<int,3>>queries;
    for(int i=0;i<q;i++){
        int l,r;cin>>l>>r;
        queries.push_back({l-1,r-1,i});
    }
    Mos mo;
    mo.process(a,queries);
}
