Cod sursa(job #2820880)

Utilizator UnknownPercentageBuca Mihnea-Vicentiu UnknownPercentage Data 21 decembrie 2021 20:11:41
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

inline void Open(const string Name) {
    #ifndef ONLINE_JUDGE
        (void)!freopen((Name + ".in").c_str(), "r", stdin);
        (void)!freopen((Name + ".out").c_str(), "w", stdout);
    #endif
}

unordered_map <int, int> H;

int N, L, U, cnt;

long long ans;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    Open("secv5");

    cin >> N >> L >> U;

    vector <int> v(N + 1);
    for(int i = 1, j = 1;i <= N;i++) {
        cin >> v[i];
        H[v[i]]++, cnt += (H[v[i]] == 1);
        while(cnt > U) {
            H[v[j]]--, j++;
            cnt -= (H[v[j]] == 0);
        }

        if(cnt >= L) {
            ans += (i - H[v[i]]) - j + 1;
        }
    }

    cout << ans;


    return 0;
}