Pagini recente » Cod sursa (job #1319088) | Cod sursa (job #1543434) | Cod sursa (job #1360323) | Cod sursa (job #2722669) | Cod sursa (job #336641)
Cod sursa(job #336641)
#include<cstdio>
#include<vector>
using namespace std;
const unsigned int m = 699967;
const unsigned int N = (1<<20);
vector<unsigned int> h[2][m];
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';
}
}
void calcul()
{
long long rez=0;
bool ex;
unsigned int i,r;
int nra=0,nrb=0,pa=-1,pb=-1;
for(i=0;i<n;++i)
{
r=v[i]%m;
ex=false;
for(vector<unsigned int>::iterator it=h[0][r].begin() ; it!=h[0][r].end() ; ++it)
if(*it==v[i])
ex=true;
if(!ex)
++nra;
h[0][r].push_back(v[i]);
while(nra==a)
{
++pa;
r=v[pa]%m;
for(vector<unsigned int>::iterator it=h[0][r].begin() ; it!=h[0][r].end() ; ++it)
if(*it==v[pa])
{
h[0][r].erase(it);
break;
}
ex=false;
for(vector<unsigned int>::iterator it=h[0][r].begin() ; it!=h[0][r].end() ; ++it)
if(*it==v[pa])
ex=true;
if(!ex)
--nra;
}
r=v[i]%b;
ex=false;
for(vector<unsigned int>::iterator it=h[1][r].begin() ; it!=h[1][r].end() ; ++it)
if(*it==v[i])
ex=true;
if(!ex)
++nrb;
h[1][r].push_back(v[i]);
while(nrb>b)
{
++pb;
r=v[pb]%m;
for(vector<unsigned int>::iterator it=h[1][r].begin() ; it!=h[1][r].end() ; ++it)
if(*it==v[pb])
{
h[1][r].erase(it);
break;
}
ex=false;
for(vector<unsigned int>::iterator it=h[1][r].begin() ; it!=h[1][r].end() ; ++it)
if(*it==v[pb])
ex=true;
if(!ex)
--nrb;
}
rez+=pa-pb;
}
printf("%lld\n",rez);
}
int main()
{
freopen("secv5.in","r",stdin);
freopen("secv5.out","w",stdout);
citire();
calcul();
return 0;
}