Cod sursa(job #2759069)

Utilizator VladPislaruPislaru Vlad Rares VladPislaru Data 15 iunie 2021 10:41:06
Problema Secventa 5 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
/*
    utilizare unordered_map
*/
#include <bits/stdc++.h>

using namespace std;

unsigned a[1100000];
int n, L, U;

long long Rezolva(unsigned t)
{
    unordered_map <unsigned, int> h;
    long long sol = 0, last = 1;
    for(int i = 1; i <= n; i++)
    {
        h[a[i]]++;
        while(h.size() > t)
        {
            h[a[last]]--;
            if(h[a[last]]==0)
                h.erase(a[last]);
            last++;
        }
        sol += (i - last + 1);
    }
    return sol;
}
int main()
{
    ifstream fin("secv5.in");
    ofstream fout("secv5.out");
    fin >> n >> L >> U;
    for(int i = 1; i <= n; i++)
        fin >> a[i];
    fout << (Rezolva(U) - Rezolva(L - 1)) << "\n";
    fin.close();
    fout.close();
    return 0;
}