Cod sursa(job #3276297)

Utilizator aadsafafdfAlexandru Spermezist aadsafafdf Data 13 februarie 2025 09:59:04
Problema Secventa 5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#ifdef LOCAL
#include <bits/stdc++.h>
using namespace std;
ifstream fin("file.in");
ofstream fout("file.out");
#else
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
#endif

long long n;
long long v[2000005],l,u;


long long panetone(long long x)
{
    unordered_map<long long ,long long>m;
    long long st=0,elem=0,ans=0;
    for(long long dr=1;dr<=n;++dr)
    {
        m[v[dr]]++;
        if(m[v[dr]]==1)
        {
            elem++;
            while(x<elem)
            {
                st++;
                m[v[st]]--;
                if(m[v[st]]==0)elem--;
            }
        }
        ans+=dr-st;
    }
    return ans;
}



int main()
{

    fin>>n>>l>>u;
    for(long long i=1;i<=n;++i)
    {
        fin>>v[i];
    }
    //cout<<panetone(u)<<" "<<panetone(l-1);

    fout<<panetone(u)-panetone(l-1);


    return 0;
}