Cod sursa(job #2877973)

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

using namespace std;

int N, L, U, V[10000] = {};
int functie(int k){
    unordered_map<int, int> 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(){
    freopen("secv5.in", "r", stdin);
    freopen("secv5.out", "w", stdout);
    cin>>N>>L>>U;
    for(int i=0; i<N; i++)
        cin>>V[i];
    cout<<functie(U);
}