Cod sursa(job #1566161)

Utilizator sulzandreiandrei sulzandrei Data 11 ianuarie 2016 20:26:00
Problema Secventa 5 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <cmath>
using namespace std;
ifstream in("secv5.in");
ofstream out("secv5.out");
const int MAX_SIZE = ( 1 << 20 )+1;
unsigned long long  v[MAX_SIZE],n;
unsigned long long  distsec(int nr)
{
    unordered_map<unsigned long long  ,int> h;
    unsigned long long  sol = 0 ,
    to_remove = 1;
    for(int i= 1 ; i <= n ; i++)
    {
        h[v[i]]++;
        while(h.size()> nr)
        {
            h[v[to_remove]]--;
            if(h[v[to_remove]]==0)
                h.erase(v[to_remove]);
            to_remove++;
        }
        sol += i-to_remove +1;          //updatam numarul de subsiruri
    }
    return sol;
}
int main()
{
    int l,u;
    in >> n >> u >> l;
    for(int i = 1  ; i <= n ; i++)
        in >> v[i];
    unsigned long long  first = distsec(l);
    unsigned long long  second = distsec(u-1);
    out<<first-second;
    return 0;
}