Cod sursa(job #1687045)

Utilizator tudormaximTudor Maxim tudormaxim Data 12 aprilie 2016 17:22:42
Problema Secventa 5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;

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

const int nmax = (1<<20) + 5;
int n, l, u;
unsigned int v[nmax];
unordered_map <unsigned int, int> h;

long long subsecv(int x) {
    h.clear();
    long long sol=0;
    int j=1, i;
    for(i=1; i<=n; i++) {
        h[v[i]]++;
        while(h.size() > x) {
            h[v[j]]--;
            if(h[v[j]]==0) h.erase(v[j]);
            j++;
        }
        sol+=(i-j+1);
    }
    return sol;
}

int main() {
    ios_base::sync_with_stdio(false);
    int i;
    fin >> n >> l >> u;
    for(i=1; i<=n; i++)
        fin >> v[i];
    fout << subsecv(u)-subsecv(l-1);
    fin.close();
    fout.close();
    return 0;
}