Cod sursa(job #2908595)

Utilizator yo_andrei_2003Murica Andrei yo_andrei_2003 Data 4 iunie 2022 16:59:10
Problema Secventa 5 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
#include <iostream>
#include <unordered_map>
#include<iterator>

using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");

int n, m, t, b, u, l;
unsigned int v[1048576];
long long raspuns(unsigned int x) {
    unordered_map<unsigned int, int> w;
    long long r=0;
    int i, j=0;
    for(i=0;i<n;i++) {
        w[v[i]]++;
        while(w.size()>x) {
            w[v[j]]--;
            if (w[v[j]]==0) {
                w.erase(v[j]);
            }
            j++;
        }
        r=r+i-j+1;
    }
    return r;
}
int main() {
    int i;
    fin>>n>>u>>l;
    for(i=0;i<n;i++) {
        fin>>v[i];
    }
    fout<<raspuns(l)-raspuns(u-1);
    return 0;
}