Cod sursa(job #1252463)

Utilizator Theodor1000Cristea Theodor Stefan Theodor1000 Data 30 octombrie 2014 19:37:26
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.41 kb
#include <cstdio>
#include <vector>
#include <algorithm>

#define M 666013
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ui unsigned int

using namespace std;

const int NMAX = (1 << 20) + 10;
ui v[NMAX];

int n, l, u, d;

vector < pair <ui, int> > h[M];

void add (ui x)
{
    int ind = x % M;
    bool OK = false;

    for (int i = 0; i < h[ind].size () && !OK; ++i)
        if (h[ind][i].f == x) ++h[ind][i].s, OK = true;

    if (!OK) h[ind].pb (mp (x, 1)), ++d;
}

void del (ui x)
{
    int ind = x % M;
    for (int i = 0; i < h[ind].size (); ++i)
        if (h[ind][i].f == x)
        {
            --h[ind][i].s;
            if (!h[ind][i].s) --d;
        }
}

long long scv (int lim)
{
    int a = 1, b = 1;
    long long rez = 0LL;
    d = 0;

    for (int i = 0; i < M; ++i)
        h[i].clear ();

    while (b <= n)
    {
        add (v[b]);

        while (d > lim)
        {
            del (v[a]);
            ++a;
        }

        rez += 1LL * (1LL * b - 1LL * a + 1LL);
        ++b;
    }

    return rez;
}

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

    scanf ("%d %d %d", &n, &l, &u);

    for (int i = 1; i <= n; ++i)
        scanf ("%u", &v[i]);

    long long nr = 1LL * (1LL* scv (u) - 1LL * scv (l - 1));
    printf ("%lld\n", nr);

    return 0;
}