Cod sursa(job #3353948)

Utilizator Dani111Gheorghe Daniel Dani111 Data 12 mai 2026 21:02:46
Problema Secventa 5 Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <bits/stdc++.h>
using namespace std;


int main() {
    freopen("secv5.in", "r", stdin);
    freopen("secv5.out", "w", stdout);
    int N, L, U;
    cin >> N >> L >> U;

    vector<int>A(N + 3);
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    int left = 1, right = 1;
    unordered_map<int, int>multe, putine;
    long long ans = 0;
    for(int i = 1; i <= N; i++) {
        putine[A[i]]++;
        multe[A[i]]++;

        bool ok = 0;
        while(putine.size() >= L) {
            putine[A[right]]--;
            if(putine[A[right]] == 0) putine.erase(A[right]);
            right++;
            ok = 1;
        }
        if(ok) {
            right--;
            putine[A[right]]++;
        }

        while(multe.size() > U) {
            multe[A[left]]--;
            if(multe[A[left]] == 0) multe.erase(A[left]);
            left++;
        }
        if(putine.size() == L) {
            // cout << left << ' ' << right << ' ' << i << '\n';
            ans += right - left + 1;
        }
    }

    cout << ans;
}