Cod sursa(job #3267949)

Utilizator CosminaneBoac Mihai Cosmin Cosminane Data 13 ianuarie 2025 09:38:02
Problema Secventa 5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <fstream>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
unordered_map <unsigned int, int> f;
vector <unsigned int> v;
vector <int> r;
int main(){
    int n, l, u, i, j, tot;
    unsigned int x;
    long long ras;
    ifstream fin( "secv5.in" );
    ofstream fout( "secv5.out" );
    fin >> n >> l >> u;
    tot = j = 0;
    for( i = 0; i < n; i++ ){
        fin >> x;
        v.push_back( x );
        f[x]++;
        if( f[x] == 1 ){
            tot++;
        }
        while( tot > u ){
            f[v[j]]--;
            if( f[v[j]] == 0 ){
                tot--;
            }
            j++;
        }
        r.push_back( j );
    }
    for( i = 0; i < n; i++ ){
        f[v[i]] = 0;
    }
    tot = j = ras = 0;
    for( i = 0; i < n; i++ ){
        x = v[i];
        f[x]++;
        if( f[x] == 1 ){
            tot++;
        }
        while( tot >= l ){
            f[v[j]]--;
            if( f[v[j]] == 0 ){
                tot--;
            }
            j++;
        }
        ///cout << i << ' ' << tot << ' ' << x << ' ' << j << ' ' << r[i] << '\n';
        ras += j - r[i];
    }
    fout << ras;
    return 0;
}