Cod sursa(job #2891088)

Utilizator hobbitczxdumnezEU hobbitczx Data 17 aprilie 2022 15:02:54
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("secv5.in");
ofstream fout ("secv5.out");

const int N_MAX = (1 << 20) + 5;

int a[N_MAX] , n , k , w , ans , l , r , cnt;
unordered_map<int , int>mp;

int main(){
    ios_base::sync_with_stdio(false);
    fin.tie(NULL);
    fin >> n >> k >> w;
    for (int i=1; i<=n; i++){
        fin >> a[i];
    }
    l = 1 , r = 1;
    while (r <= n){
        if (mp[a[r]] == 0){
            cnt += 1;
        }
        mp[a[r]] += 1;
        if (cnt >= k){
            while (cnt >= w){
                if (mp[a[l]] == 1){
                    cnt -= 1;
                }
                mp[a[l]] -= 1;
                l += 1;
            }
            if (cnt >= k){
                ans += r - l + 1;
            }
        }
        r += 1;
    }
    fout << ans;
}