Cod sursa(job #3273853)

Utilizator mateistefan11matei stefan mateistefan11 Data 4 februarie 2025 10:20:20
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
int n,l,u, a[1000005];
map<int, int> M;
int main()
{
    int i, x,j;
    ios::sync_with_stdio(0);
    fin.tie(0);
    fout.tie(0);
    fin >> n >> l >> u;
    for(i = 1; i <= n; i++)
    {
        fin >> a[i];
        M[a[i]] = 1;
    }
    int k = 0;
    for(auto &e : M)
        e.second = ++k;
    for(i = 1; i <= n;  i++)
        a[i] = M[a[i]];
    int sol = 0;
    for(i = 1; i <= n; i++)
    {
        int cnt = 0;
        M.clear();
        for(j = i; j <= n; j++)
        {
            M[a[j]]++;
            if(M[a[j]] == 1)
                cnt++;
            if(cnt >= l && cnt <= u) sol++;
        }
    }
    fout << sol;
    return 0;
}