Cod sursa(job #3276468)

Utilizator Minea_TheodorMinea Theodor Stefan Minea_Theodor Data 13 februarie 2025 18:39:49
Problema Secventa 5 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
unsigned int v[1048577];
int n;
long long f(int x)
{
    unordered_map<int, int> mapa;
    int st=1,cnt=0;
    long long rez=0;
    for(int i=1; i<=n; i++)
    {
        mapa[v[i]]++;
        if(mapa[v[i]]==1)
            cnt++;
        while(cnt>x)
        {
            mapa[v[st]]--;
            if(mapa[v[st]]==0)
                cnt--;
            st++;
        }
        rez+=i-st+1;
    }
    return rez;
}
int main()
{
    int u,l;
    fin>>n>>l>>u;
    for(int i=1; i<=n; i++)
        fin>>v[i];
    fout<<f(u)-f(l-1);
    return 0;
}