Cod sursa(job #3326124)

Utilizator 76.alexxAlex Istrate 76.alexx Data 27 noiembrie 2025 14:10:30
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
#include <unordered_map>
#include <vector>
using namespace std;

ifstream cin("secv5.in");
ofstream cout("secv5.out");

int n, x, y;
vector <int> a(n+5);

int yan(int t, int n){
    unordered_map<long long, int> m;
    int l=1, cnt=0, ans=0;
    for(int r=1;r<=n;r++){
        m[a[r]]++;
        if(m[a[r]]==1) cnt++;
        while(l<=r && cnt>t){
            m[a[l]]--;
            if(m[a[l]]==0) cnt--;
            l--;
        }
        ans+=(r-l+1);
    }
    return ans;
}

int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    cout<<yan(y, n)-yan(x-1, n);
}