Pagini recente » Cod sursa (job #522686) | Cod sursa (job #1607218) | Cod sursa (job #2271202) | Cod sursa (job #1543848) | Cod sursa (job #336625)
Cod sursa(job #336625)
#include<cstdio>
#include<vector>
using namespace std;
const unsigned int m = 699967;
const int lim = (1<<4);
const unsigned int N = (1<<20);
unsigned int ha[m][lim],hb[m][lim];
unsigned int n,v[N];
int a,b;
void citire()
{
char s[11],*p;
scanf("%u%u%u\n",&n,&a,&b);
for(unsigned int i=0;i<n;++i)
{
scanf("%s\n",s);
for(p=s;*p;++p)
v[i]=v[i]*10+*p-'0';
}
}
bool exista(unsigned int h[m][lim],unsigned int x)
{
unsigned int i,r=x%m;
for(i=1;i<=h[r][0];++i)
if(h[r][i]==x)
return true;
return false;
}
void sterge(unsigned int h[m][lim],unsigned int x)
{
unsigned int r=x%m,i;
for(i=1;i<=h[r][0];++i)
if(h[r][i]==x)
{
h[r][i]=0;
return;
}
}
inline void adauga(unsigned int h[m][lim],unsigned int x)
{
unsigned int r=x%m;
h[r][++h[r][0]]=x;
}
void calcul()
{
long long rez=0;
unsigned int i;
int nra=0,nrb=0,pa=-1,pb=-1;
for(i=0;i<n;++i)
{
if(!exista(ha,v[i]))
++nra;
adauga(ha,v[i]);
while(nra==a)
{
sterge(ha,v[++pa]);
if(!exista(ha,v[pa]))
--nra;
}
if(!exista(hb,v[i]))
++nrb;
adauga(hb,v[i]);
while(nrb>b)
{
sterge(hb,v[++pb]);
if(!exista(hb,v[pb]))
--nrb;
}
rez+=pa-pb;
}
printf("%lld\n",rez);
}
int main()
{
freopen("secv5.in","r",stdin);
freopen("secv5.out","w",stdout);
citire();
calcul();
return 0;
}