Cod sursa(job #12809)

Utilizator victorsbVictor Rusu victorsb Data 4 februarie 2007 21:03:32
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.99 kb
#include <cstdio>
#include <vector>

using namespace std;

#define Nmax 1048576
#define pb push_back
#define sz(a) int((a).size())

const int r1 = 12582917;
const int r2 = 666013;
const int Tmax = 196613;
int i, j, k, n, l, u, ct, last, size, h1, h2;
long long sol;
unsigned int sir[Nmax], vl;
int t1[Tmax][5], t2[Tmax][5];

int s[Nmax];

inline void citire()
{
    scanf("%d %d %d\n", &n, &l, &u);
    for (i=1; i<=n; ++i)
        scanf("%u\n", &sir[i]);
}
/*
inline long long solve2(int m)
{
    int st = 1, ct = 0, dr;
    long long ret = 0;
    for (dr=1; dr<=n; ++dr)
    {
        if (!v[s[dr]])
            ++ct;
        ++v[s[dr]];
        while (ct > m)
        {
            if (v[s[st]] == 1)
                --ct;
            --v[s[st]];
            ++st;
        }
        ret += dr - st + 1;
    }
    for (; st<=n; ++st)
        --v[s[st]];
    return ret;
}
*/
inline int hash1(unsigned int x)
{
    long long p = x;
    return (p * r1) % Tmax;
}

inline int hash2(unsigned int x)
{
    long long p = x;
    return (p * r2) % Tmax;
}

inline int find(int x)
{
    int i;
    for (i=1; i<=t1[h1][0]; ++i)
        if (vl == sir[t1[h1][i]])
        {
            s[x] = s[t1[h1][i]];
            return 1;
        }
    for (i=1; i<=t2[h2][0]; ++i)
        if (vl == sir[t2[h2][i]])
        {
            s[x] = s[t2[h2][i]];
            return 1;
        }
    return 0;
}

inline void solve()
{
    for (i=1; i<=n; ++i)
    {
        vl = sir[i];
        h1 = hash1(vl);
        h2 = hash2(vl);
        if (!find(i))
        {
            s[i] = ++ct;
            if (t1[h1][0] < t2[h2][0])
                t1[h1][++t1[h1][0]] = i;
            else
                t2[h2][++t2[h2][0]] = i;
        }
    }
    //sol = solve2(u);
    //sol -= solve2(l-1);
    //printf("%lld\n", sol);
}

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