Cod sursa(job #3276292)

Utilizator AndreiStrugureAndrei AndreiStrugure Data 13 februarie 2025 09:47:38
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#ifdef LOCAL
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fantastice.in");
ofstream fout("fantastice.out");
#else
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
#endif
int n, l, u;
int v[1050000];
unordered_map<long long, int> mp;
int twop(int mx){
    mp.clear();
    long long cnt=0, nr=1;
    int s=1, d=1;
    mp[v[1]]++;
    while(s<=n && d<=n){
        cnt+=d-s+1;
        while(mp[v[d+1]]==0 && nr==mx){
            //cout<<s<<" "<<d<<'\n';
            mp[v[s]]--;
            if(mp[v[s]]==0){
                nr--;
                mp.erase(v[s]);
            }
            s++;
        }
        d++;
        mp[v[d]]++;
        if(mp[v[d]]==1) nr++;
    }
    //cout<<cnt<<"\n";
    return cnt;
}


int main()
{
    fin>>n>>l>>u;
    for(int i=1; i<=n; i++){
        fin>>v[i];
    }
    if(l>=2)fout<<twop(u)-twop(l-1);
    else fout<<twop(u);


    return 0;
}