Pagini recente » Arhiva de probleme | Cod sursa (job #771018) | Cod sursa (job #531746) | Cod sursa (job #2197675) | Cod sursa (job #906087)
Cod sursa(job #906087)
#include<cstdio>
#include<cstring>
#include<vector>
#define M 666013
#define NMax (1<<20)+5
using namespace std;
unsigned v[NMax];
int n,l,u;
vector<pair<unsigned,int> > a[M];
vector<pair<unsigned,int> >::iterator poz[NMax];
inline vector<pair<unsigned,int> >::iterator find (unsigned x)
{
vector<pair<unsigned,int> >::iterator it;
for (it=a[x%M].begin(); it!=a[x%M].end(); ++it)
if (it->first==x)
return it;
return a[x%M].end();
}
void hash ()
{
vector<pair<unsigned,int> >::iterator it;
int i;
for (i=1; i<=n; i++)
{
it=find(v[i]);
if (it==a[v[i]%M].end())
{
a[v[i]%M].push_back(make_pair(v[i],0));
it=find(v[i]);
}
poz[i]=it;
}
}
void reset (int x)
{
int i;
for (i=x; i<=n; i++)
poz[i]->second=0;
}
long long sol (int x)
{
if (!x) return 0;
int nr=1,st=1,i;
long long sum=1,aux;
poz[1]->second=1;
for (i=2; i<=n; i++)
{
if (poz[i]->second==0)
nr++;
poz[i]->second++;
while (nr>x)
{
if (poz[st]->second==1)
nr--;
poz[st]->second--;
st++;
}
aux=(long long)(i-st+1);
sum+=aux;
}
if (x==u) reset(st);
return sum;
}
int main ()
{
char s[10];
int i,lg,j;
freopen("secv5.in","r",stdin);
freopen("secv5.out","w",stdout);
scanf("%d%d%d",&n,&l,&u);
for (i=1; i<=n; i++)
{
scanf("%s",s);
lg=strlen(s);
for (j=0; j<lg; j++)
v[i]=v[i]*10+(s[j]-'0');
}
hash();
printf("%lld\n",sol(u)-sol(l-1));
return 0;
}