Cod sursa(job #2877985)

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

using namespace std;

long long N, L, U, V[10000];
long long functie(int k){
    unordered_map<long long, 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);
}