Pagini recente » test193120947281 | Cod sursa (job #1941229) | Cod sursa (job #156678) | Cod sursa (job #2221231) | Cod sursa (job #1768078)
#include<bits/stdc++.h>
#define C 666013
#define dim 1000005
using namespace std;
vector<pair<int,int> > h1[C+5],h2[C+5];
vector<pair<int,int> >::iterator it;
char buff[dim+5];
int poz=0,d1,d2,i1,i2,sol;
unsigned int v[1<<20+5];
unsigned int n,l,u;
void citeste(unsigned int &numar)
{
numar=0;
while (buff[poz]<'0' || buff[poz]>'9')
{
poz++;
if (poz==dim)
{
fread(buff,1,dim,stdin);
poz=0;
}
}
while (buff[poz]>='0' && buff[poz]<='9')
{
numar=numar*10+buff[poz]-'0';
poz++;
if (poz==dim)
{
fread(buff,1,dim,stdin);
poz=0;
}
}
}
//functii pe primul hash
int find(unsigned int x)
{
unsigned int y=x%C;
for(it=h1[y].begin();it!=h1[y].end();it++)
{
if((*it).first==x)
{
(*it).second++;
// d1++;
return 1;
}
}
return 0;
}
void add(unsigned int x)
{
if(find(x)) return;
unsigned int y=x%C;
h1[y].push_back(make_pair(x,1));
d1++;
}
void erase(unsigned int x)
{
unsigned int y=x%C;
for(it=h1[y].begin();it!=h1[y].end();it++)
{
if((*it).first==x)
{
(*it).second--;
if (!(*it).second)
{
d1--;
h1[y].erase(it);
}
return;
}
}
}
///////////
/////// functii pe al doilea hash
int find1(unsigned int x)
{
unsigned int y=x%C;
for(it=h2[y].begin();it!=h2[y].end();it++)
{
if((*it).first==x)
{
//d2++;
(*it).second++;
return 1;
}
}
return 0;
}
void add1(unsigned int x)
{
if(find1(x)) return;
unsigned int y=x%C;
d2++;
h2[y].push_back(make_pair(x,1));
}
void erase1(unsigned int x)
{
unsigned int y=x%C;
for(it=h2[y].begin();it!=h2[y].end();it++)
{
if((*it).first==x)
{
(*it).second--;
if (!(*it).second)
{
d2--;
h2[y].erase(it);
}
return;
}
}
}
/////////
int main()
{
freopen("secv5.in","r",stdin);
freopen("secv5.out","w",stdout);
fread(buff,1,dim,stdin);
citeste(n);
citeste(l);
citeste(u);
i1=i2=1;
for(unsigned int i=1;i<=n;i++)
{
citeste(v[i]);
add(v[i]);
add1(v[i]);
while(i1<=i && d1>=l)
{
erase(v[i1]);
i1++;
}
while(i2<=i && d2>u)
{
erase1(v[i2]);
i2++;
}
if(d2>=l) sol=sol+(i1-i2);
}
printf("%d\n",sol);
}