Cod sursa(job #1459354)

Utilizator mirupetPetcan Miruna mirupet Data 9 iulie 2015 17:15:21
Problema Secventa 5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include<cstdio>
#include<unordered_map>
#define dim (1<<20) + 2
using namespace std;

long long int n,L,U;
unsigned int v[dim];

unordered_map<unsigned int, unsigned int> H;


inline long long int Secv(int nr)
{
    long long int rez = 0;
    int i, j;

    for(i = 0, j = 0; i < n; ++i)
    {
        ++H[v[i]];

        while( H.size() > nr )
        {
            --H[v[j]];
            if( !H[v[j]] )
                H.erase(v[j]);
            ++j;
        }
        rez += 1LL * ( i - j + 1 );
    }
    return rez;
}

int main()
    {
        freopen("secv5.in","r",stdin);
        freopen("secv5.out","w",stdout);
        scanf("%lld%lld%lld", &n, &L, &U);
        unsigned long long a, b;
        for ( int k = 0; k < n; k++)
            scanf("%ud", &v[k]);

        a= Secv(U);
        H.clear();
        b= Secv(L - 1);

        printf("%lld", a - b);
    }