Cod sursa(job #1322655)

Utilizator priestnoobFMI - Dan Nema priestnoob Data 20 ianuarie 2015 11:26:49
Problema Secventa 5 Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 0.76 kb
#include<stdio.h>
#include<unordered_map>
using namespace std;

const int NMAX = (1 << 20) + 1;

long long v[NMAX];
unordered_map<unsigned int, unsigned int> h;
int n,l,u;

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

void solve()
{
    scanf("%d%d%d",&n,&l,&u);
    for(int i=1;i<=n;++i) scanf("%lld",&v[i]);
    printf("%lld",secv(u)-secv(l-1));
}


int main()
{
    freopen("secv5.in","r",stdin);
    freopen("secv5.out","w",stdout);
    solve();
}