Cod sursa(job #1565488)

Utilizator dnprxDan Pracsiu dnprx Data 10 ianuarie 2016 21:01:33
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
/*
    utilizare unordered_map
*/
#include <bits/stdc++.h>
#define L long long

using namespace std;

unsigned a[1100000];
int n, L, U;

L Rezolva(unsigned t)
{
    unordered_map <unsigned, int> h;
    L sol = 0, last = 1;
    for(int i = 1; i <= n; i++)
    {
        h[a[i]]++;
        while(h.size() > t)
        {
            h[a[last]]--;
            if(h[a[last]]==0)
                h.erase(a[last]);
            last++;
        }
        sol += (i - last + 1);
    }
    return sol;
}
int main()
{
    ifstream fin("secv5.in");
    ofstream fout("secv5.out");
    fin >> n >> L >> U;
    for(int i = 1; i <= n; i++)
        fin >> a[i];
    fout << (Rezolva(U) - Rezolva(L - 1)) << "\n";
    fin.close();
    fout.close();
    return 0;
}