Cod sursa(job #828590)

Utilizator oana_popfmi - pop oana oana_pop Data 3 decembrie 2012 22:59:58
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.59 kb
#include <cstdio>
#include <cstring>
#include <vector>


using namespace std;

#define mod 666013
#define max 1<<20



vector < int > a , b;
vector< pair < unsigned int , int > > Hash[666014];
int N,L,U,viz[max];



int search(unsigned int x)
{
     int cheie=x%mod;
     for(int i=0; i<Hash[cheie].size(); i++)
     {
        if(Hash[cheie][i].first==x)
          return Hash[cheie][i].second;
     }
     return -1;
}

long long subseq(int x)
{
     memset(viz,0,sizeof(viz));
    
     int nr=0,i=0,j=0;
     long long rez=0;
     for(; i<N; i++)
     {
              if(viz[b[i]]==0) nr++;
              viz[b[i]]++;
              for(;nr>x;j++)
              {
                               viz[b[j]]--;
                               if(!viz[b[j]]) nr--;
              }
              rez+=i-j+1;
     }
     return rez;
}

void read()
{
     scanf("%d %d %d" ,&N , &L , &U);
     int norm=0;
     for(int i=0; i<N; i++)
     {
             int x;
             scanf("%u",&x);
             a.push_back(x);
             int rez=search(x);
             if(rez==-1)
             {
                        int cheie=x%mod;
                        Hash[cheie].push_back(make_pair(x,norm));
                        b.push_back(norm++);
             }
             else
             { 
                         b.push_back(rez);
             }
     }
}

void write()
{
    printf("%lld", subseq(U)-subseq(L-1)); 
}


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