Cod sursa(job #2868648)

Utilizator tomaionutIDorando tomaionut Data 11 martie 2022 08:49:22
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
int n, l, u, a[1100000];
unordered_map <int, int> M;
long long Nr(int x)
{
    int i, p = 1, cnt = 0;
    long long sol = 0;
    for (i = 1; i <= n; i++)
    {
        M[a[i]]++;
        if (M[a[i]] == 1)
            cnt++;
        while (cnt > x)
        {
            M[a[p]]--;
            if (M[a[p]] == 0)
                cnt--;
            p++;
        }
        sol += (i - p + 1);
    }
    return sol;
}
int main()
{
    long long i, x, y;
    fin >> n >> l >> u;
    for (i = 1; i <= n; i++)
        fin >> a[i];
    x = Nr(u);
    M.clear();
    y = Nr(l - 1);
    fout << x - y << "\n";



    return 0;
}