Pagini recente » Cod sursa (job #969165) | Cod sursa (job #2878533) | Cod sursa (job #309874) | Cod sursa (job #1090653) | Cod sursa (job #671381)
Cod sursa(job #671381)
#include<stdio.h>
#include<vector>
#include<algorithm>
#define prim 123457
using namespace std;
vector<pair<unsigned,unsigned> >hhash[123460];
unsigned v[1100000];
#define DIM 10
char buff[DIM+16];
int pz;
inline void citeste(unsigned &x)
{
x=0;
while((buff[pz]<'0' || buff[pz]>'9') && (buff[pz]!='-'))
if(++pz==DIM)fread(buff, 1, DIM, stdin), pz=0;
while(buff[pz]>='0' && buff[pz]<='9')
{
x=x*10+buff[pz]-'0';
if(++pz==DIM)fread(buff,1, DIM, stdin),pz=0;
}
}
int existenta(unsigned citit)
{
unsigned i,cheie=citit%prim,lungime=hhash[cheie].size();
for(i=0;i<lungime;i++)
if(citit==hhash[cheie][i].first&&hhash[cheie][i].second!=0)
{
hhash[cheie][i].second++;
return 1;
}
pair<unsigned,unsigned>aux;
aux=make_pair(citit,1);
hhash[cheie].push_back(aux);
return 0;
}
int stergere(unsigned citit)
{
unsigned i,cheie=citit%prim,lungime=hhash[cheie].size();
for(i=0;i<lungime;i++)
if(citit==hhash[cheie][i].first&&hhash[cheie][i].second!=0)
{
hhash[cheie][i].second--;
if(hhash[cheie][i].second==0)
return 0;
else
return 1;
}
}
int main()
{
unsigned x,y,i,N,L,U,citit,indice_inceput=0,indice_sfarsit=0;
unsigned contor_distincte=0;
unsigned contor_U=0;
unsigned contor_L=0;
freopen("secv5.in","r",stdin);
freopen("secv5.out","w",stdout);
scanf("%u%u%u",&N,&L,&U);
for(i=0;i<N;i++)
citeste(v[i]);
for(i=0;i<N;i++)
{
indice_sfarsit=i;
y=existenta(v[i]);
if(!y)
contor_distincte++;
while(contor_distincte>U)
{
x=stergere(v[indice_inceput]);
if(x)
indice_inceput++;
else
{
contor_distincte--;
indice_inceput++;
}
}
contor_U+=(indice_sfarsit-indice_inceput+1);
}
for(i=0;i<123459;i++)
hhash[i].clear();
indice_inceput=0;
contor_distincte=0;
L--;
for(i=0;i<N;i++)
{
indice_sfarsit=i;
y=existenta(v[i]);
if(!y)
contor_distincte++;
while(contor_distincte>L)
{
x=stergere(v[indice_inceput]);
if(x)
indice_inceput++;
else
{
contor_distincte--;
indice_inceput++;
}
}
contor_L+=(indice_sfarsit-indice_inceput+1);
}
printf("%u",contor_U-contor_L);
return 0;
}