Pagini recente » Cod sursa (job #1582242) | Cod sursa (job #2756559) | Cod sursa (job #1582202) | Cod sursa (job #3128496) | Cod sursa (job #336603)
Cod sursa(job #336603)
#include<cstdio>
#include<vector>
using namespace std;
const int m = 699967;
const int N = (1<<20);
vector<int> ha[m],hb[m];
unsigned int n,v[N];
int a,b;
void citire()
{
scanf("%u%u%u",&n,&a,&b);
for(unsigned int i=0;i<n;++i)
scanf("%u",&v[i]);
}
bool exista(vector<int> h[m],int x)
{
int r=x%m;
for(vector<int>::iterator it=h[r].begin() ; it!=h[r].end() ; ++it)
if(*it==x)
return true;
return false;
}
void sterge(vector<int> h[m],int x)
{
int r=x%m;
for(vector<int>::iterator it=h[r].begin() ; it!=h[r].end() ; ++it)
if(*it==x)
{
h[r].erase(it);
return;
}
}
void adauga(vector<int> h[m],int x)
{
int r=x%m;
h[r].push_back(x);
}
void calcul()
{
long long rez=0;
unsigned int i;
int aux,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)
{
aux=v[++pa];
sterge(ha,v[pa]);
if(!exista(ha,aux))
--nra;
}
if(!exista(hb,v[i]))
++nrb;
adauga(hb,v[i]);
while(nrb>b)
{
aux=v[++pb];
sterge(hb,v[pb]);
if(!exista(hb,aux))
--nrb;
}
rez+=pa-pb;
}
printf("%lld\n",rez);
}
int main()
{
freopen("secv5.in","r",stdin);
freopen("secv5.out","w",stdout);
citire();
calcul();
return 0;
}