Pagini recente » Cod sursa (job #1876007) | Cod sursa (job #2133496) | Cod sursa (job #1216925) | Cod sursa (job #1997240) | Cod sursa (job #664565)
Cod sursa(job #664565)
#include<stdio.h>
#include<vector>
#define prim 123457
using namespace std;
vector<unsigned int>hhash[123460];
vector<unsigned int>frecv[123460];
vector<unsigned int>v;
int existenta(unsigned int citit)
{
unsigned int i,cheie=citit%prim;
for(i=0;i<hhash[cheie].size();i++)
if(citit==hhash[cheie][i]&&frecv[cheie][i]!=0)
return 1;
return 0;
}
void actualizare(unsigned int citit)
{
unsigned int i,cheie=citit%prim;
for(i=0;i<hhash[cheie].size();i++)
if(citit==hhash[cheie][i])
{
frecv[cheie][i]++;
return;
}
hhash[cheie].push_back(citit);
frecv[cheie].push_back(1);
}
void stergere(unsigned int citit)
{
unsigned int i,cheie=citit%prim,lungime=hhash[cheie].size();
for(i=0;i<lungime;i++)
if(citit==hhash[cheie][i])
{
frecv[cheie][i]--;
return;
}
}
int main()
{
unsigned int i,N,L,U,citit,indice_inceput=0,indice_sfarsit=0;
unsigned int contor_distincte=0;
unsigned int contor_U=0;
unsigned int contor_L=0;
freopen("secv5.in","r",stdin);
freopen("secv5.out","w",stdout);
scanf("%d%d%d",&N,&L,&U);
for(i=0;i<N;i++)
{
scanf("%d",&citit);
v.push_back(citit);
indice_sfarsit=i;
if(contor_distincte<=U)
if(existenta(citit))
{
actualizare(citit);
contor_U+=(indice_sfarsit-indice_inceput+1);
}
else
if(!existenta(citit))
{
actualizare(citit);
contor_distincte++;
if(contor_distincte<=U)
{
contor_U+=(indice_sfarsit-indice_inceput+1);
}
else
if(contor_distincte>U)
{
while(contor_distincte>U)
{
stergere(v[indice_inceput]);
if(existenta(v[indice_inceput]))
indice_inceput++;
else
{
contor_distincte--;
/*indice_inceput++;*/
}
}
contor_U+=(indice_sfarsit-indice_inceput+1);
}
}
}
for(i=0;i<123458;i++)
{
for(unsigned int j=0;j<hhash[i].size();j++)
{
hhash[i][j]=0;
frecv[i][j]=0;
}
}
indice_inceput=0;
contor_distincte=0;
L--;
for(i=0;i<N;i++)
{
indice_sfarsit=i;
if(contor_distincte<=L)
if(existenta(v[i]))
{
actualizare(v[i]);
contor_L+=(indice_sfarsit-indice_inceput+1);
}
else
if(!existenta(v[i]))
{
actualizare(v[i]);
contor_distincte++;
if(contor_distincte<=L)
{
contor_L+=(indice_sfarsit-indice_inceput+1);
}
else
if(contor_distincte>L)
{
while(contor_distincte>L)
{
stergere(v[indice_inceput]);
if(existenta(v[indice_inceput]))
indice_inceput++;
else
if(!existenta(v[indice_inceput]))
{
contor_distincte--;
indice_inceput++;
}
}
contor_L+=(indice_sfarsit-indice_inceput+1);
}
}
}
printf("%d",contor_U-contor_L);
return 0;
}