Pagini recente » Cod sursa (job #164680) | Cod sursa (job #2361166) | Cod sursa (job #1828375) | Cod sursa (job #1054928) | Cod sursa (job #671646)
Cod sursa(job #671646)
#include<stdio.h>
#include<vector>
#include<algorithm>
#define prim 123457
#define DIM 10
using namespace std;
vector<pair<unsigned,unsigned> >hhash[123460];
unsigned v[1100000];
unsigned chei[1100000];
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 cheie)
{
unsigned i,lungime=hhash[cheie].size();
for(i=0;i<lungime;i++)
{
if(citit==hhash[cheie][i].first)
if(hhash[cheie][i].second!=0)
{
hhash[cheie][i].second++;
return 1;
}
else
{
hhash[cheie][i].second++;
return 0;
}
}
hhash[cheie].push_back(make_pair(citit,1));
return 0;
}
int stergere(unsigned citit,unsigned cheie)
{
unsigned i,lungime=hhash[cheie].size();
for(i=0;i<lungime;i++)
if(citit==hhash[cheie][i].first)
if(hhash[cheie][i].second!=0)
{
hhash[cheie][i].second--;
if(hhash[cheie][i].second==0)
return 0;
else
return 1;
}
}
int main()
{
unsigned i,N,L,U,citit,indice_inceput=0;
unsigned contor_distincte=0;
long long unsigned contor_U=0;
long long 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]);
chei[v[i]]=v[i]%prim;
if(!existenta(v[i],chei[v[i]]))
{
contor_distincte++;
while(contor_distincte>U)
{
if(stergere(v[indice_inceput],chei[v[i]]))
indice_inceput++;
else
{
contor_distincte--;
indice_inceput++;
}
}
}
contor_U+=(long long unsigned)(i-indice_inceput+1);
}
for(i=indice_inceput;i<N;i++)
stergere(v[i],chei[v[i]]);
indice_inceput=0;
contor_distincte=0;
L--;
for(i=0;i<N;i++)
{
if(!existenta(v[i],chei[v[i]]))
{
contor_distincte++;
while(contor_distincte>L)
{
if(stergere(v[indice_inceput],chei[v[i]]))
indice_inceput++;
else
{
contor_distincte--;
indice_inceput++;
}
}
}
contor_L+=(long long unsigned)(i-indice_inceput+1);
}
printf("%llu",contor_U-contor_L);
return 0;
}