Cod sursa(job #2051659)

Utilizator tifui.alexandruTifui Ioan Alexandru tifui.alexandru Data 29 octombrie 2017 13:26:41
Problema Secventa 5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <bits/stdc++.h>
#define Nmax 1048580
#define ll long long
#define DIM 70000
using namespace std;
ofstream g("secv5.out");
int cursor=DIM-1;
char buffer[DIM];
void read(ll &x)
{
    x=0;
    while(buffer[cursor]<'0' or buffer[cursor]>'9')
        if(++cursor==DIM)
        {
            cursor=0;
            fread(buffer,1,DIM,stdin);
        }
    while(buffer[cursor]>='0' and buffer[cursor]<='9')
    {
        x=x*10+buffer[cursor]-'0';
        if(++cursor==DIM)
        {
            cursor=0;
            fread(buffer,1,DIM,stdin);
        }
    }
}
ll v[Nmax];
ll n,l,u;
ll solve(ll N)
{
    ll ans=0;
    unordered_map <ll,ll> M;
    ll i,p=1,nr=0;
    for(i=1;i<=n;i++)
    {
        if(!M[v[i]]) nr++;
        M[v[i]]++;
        while(nr>N)
        {
            M[v[p]]--;
            if(!M[v[p]])
            {
                --nr;
                M.erase(v[p]);
            }
            p++;
        }
        ans+=(i-p);
    }
    return ans;
}
int main()
{
    freopen("secv5.in","r",stdin);
    read(n);
    read(l);
    read(u);
    for(ll i=1;i<=n;i++)
        read(v[i]);
    g<<solve(u)-solve(l-1);

    return 0;
}