赵云1234 edited 2 年,5 月前

#include<iostream>
#include<map>
using namespace std;
int main() {
    int N, Q;
    int L, R;
    int a[100001];
    int count[5000]={0};
    cin >> N >> Q;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < Q;i++) {
        cin >> L >> R;
        map<int, int> mymap;
        for (int i = L; i <= R; i++) {
            ++mymap[a[i]];
        }
        map<int, int>::iterator it;
        for (it = mymap.begin(); it != mymap.end(); it++) {
            if (it->second == 2) {
                ++count[i];
            }
        }
    }
    for (int i = 0; i < Q; i++) {
        cout << count[i] << endl;
    }
}

Comments