Cod sursa(job #3274462)

Utilizator mateistefan11matei stefan mateistefan11 Data 6 februarie 2025 21:01:50
Problema Secventa 5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
int n, L, U;
long long a[1000005];
unordered_map<long long, int> M;
/**
        i
13 13 7 9 9

*/
long long salamakeum(int x)
{
    int i = 1, j = 1, bruh = 0;
    long long cnt = 0;
    M.clear();
    while(i <= n)
    {
        if(M[a[i]] == 0)
            bruh++;
        M[a[i]]++;
        while(bruh > x)
        {
           M[a[j]]--;
            if(M[a[j]] == 0)
                bruh--;
            j++;
        }

        cnt += (i - j + 1);
        i++;
    }
    return cnt;
}
int main()
{
    ios::sync_with_stdio(0);
    fin.tie(0);
    fout.tie(0);
    int i;
    fin >> n >> L >> U;
    for(i = 1; i <= n; i++)
        fin >> a[i];
    fout << salamakeum(U) - salamakeum(L - 1);
    return 0;
}