Cod sursa(job #3351885)

Utilizator robert_dumitruDumitru Robert Ionut robert_dumitru Data 22 aprilie 2026 00:16:43
Problema Secventa 5 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <fstream>
#include <vector>
#include <unordered_map>
using namespace std;

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

unordered_map<unsigned int, int> frU, frL;
vector<unsigned int> a;
int distinctU = 0, distinctL = 0;
int n, L, U;

int main() {
    fin >> n >> L >> U;

    a.resize(n);
    for (int i = 0; i < n; i++) fin >> a[i];

    long long total = 0;
    int stU = 0, stL = 0;

    for (int right = 0; right < n; right++) {
        if (frU[a[right]] == 0) distinctU++;
        frU[a[right]]++;

        if (frL[a[right]] == 0) distinctL++;
        frL[a[right]]++;

        while (distinctU > U) {
            frU[a[stU]]--;
            if (frU[a[stU]] == 0) distinctU--;
            stU++;
        }

        while (distinctL > L - 1) {
            frL[a[stL]]--;
            if (frL[a[stL]] == 0) distinctL--;
            stL++;
        }

        if (distinctU >= L) {
            total += (stL - stU);
        }
    }

    fout << total << endl;
    return 0;
}