Cod sursa(job #3276303)

Utilizator AndreiStrugureAndrei AndreiStrugure Data 13 februarie 2025 10:19:50
Problema Secventa 5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 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;
unsigned int v[10000002];

long long twop(int mx){
    unordered_map<unsigned int, int> mp;
    long long cnt=0, nr=0;
    int s=0, d=0;
    while(d<n){
        mp[v[d]]++;
        if(mp[v[d]]==1) nr++;
        d++;
        while(nr>mx){
            //cout<<s<<" "<<d<<'\n';
            mp[v[s]]--;
            if(mp[v[s]]==0){
                nr--;
                mp.erase(v[s]);
            }
            s++;

        }
        cnt+=d-s;
    }
    //cout<<cnt<<"\n";
    return cnt;
}


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


    return 0;
}