Cod sursa(job #2877981)

Utilizator petru.theodor07Petru Cristea petru.theodor07 Data 25 martie 2022 17:42:31
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <bits/stdc++.h>

using namespace std;

int N, L, U, V[10000];
int functie(int k){
    unordered_map<unsigned int, long long> x;
    int ct = 0;
    for(int i=0, j=0; i < N; i++) {
        x[V[i]]++;
        while (x.size() > k) {
            x[V[j]]--;
            if (x[V[j]] == 0)
                x.erase(V[j]);
            j++;
        }
        ct += i - j + 1;
    }
    return ct;
}
int main(){
    ifstream fin("secv5.in");
    ofstream fout("secv5.out");
    fin>>N>>L>>U;
    for(int i=0; i<N; i++)
        fin>>V[i];
    fout<<functie(U) - functie(L-1);
}