Cod sursa(job #1320161)

Utilizator obidanDan Ganea obidan Data 17 ianuarie 2015 17:37:38
Problema Secventa 5 Scor 90
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 0.87 kb
#include <iostream>
#include <fstream>
#include <cstdio>
#include <unordered_map>
using namespace std;

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

 int n;
unsigned int  a[NMax];
unordered_map<unsigned int,unsigned int> myhashmap;

long long int until( int x)
{
    myhashmap.clear();
    long long int  sum=0;
      int j = 1;
    for( int i = 1 ; i <= n; i++)
    {
        myhashmap[a[i]]++;
        while(x<myhashmap.size())
        {
            myhashmap[a[j]]--;
            if(myhashmap[a[j]]==0)
                myhashmap.erase(a[j]);
            j++;
        }
        sum = sum + (i - j + 1);
    }
    return sum;
}

int main()
{

     int l,u,i;
    freopen("secv5.in","r",stdin);
    freopen("secv5.out","w",stdout);
    scanf("%d %d %d",&n,&l,&u);
    for(i=1;i<=n;i++)
    {
        scanf("%ud",&a[i]);
    }
    cout<<until(u)-until(l-1);
}