Pagini recente » Cod sursa (job #735073) | Cod sursa (job #1384805) | Cod sursa (job #617693) | Cod sursa (job #2510055) | Cod sursa (job #1243851)
#include<stdio.h>
#include<vector>
using namespace std;
#define MOD 666013
#define NMAX 1050000
int n, a, b;
unsigned int v[NMAX];
int num;
vector<pair<unsigned int, int> > hashBoss[MOD];
vector<pair<unsigned int, int> >::iterator it;
void inline insert(unsigned int x)
{
int lin=x%MOD;
for(it=hashBoss[lin].begin(); it!=hashBoss[lin].end(); ++it)
{
if(it->first==x)
{
++it->second;
if(it->second==1)
++num;
break;
}
}
if(it==hashBoss[lin].end())
{
hashBoss[lin].push_back(make_pair(x, 1));
++num;
}
}
void inline erase(unsigned int x)
{
int lin=x%MOD;
for(it=hashBoss[lin].begin(); it!=hashBoss[lin].end(); ++it)
{
if(it->first==x)
{
--it->second;
if(it->second==0)
{
swap(*it, hashBoss[lin].back());
hashBoss[lin].pop_back();
--num;
}
break;
}
}
}
long long rez(int x)
{
int st=1;
long long sol=0;
for(int i=0; i<MOD; ++i)
hashBoss[i].clear();
num=0;
for(int i=1; i<=n; ++i)
{
insert(v[i]);
while(st<=i && num>x)
{
erase(v[st]);
++st;
}
sol+=(long long)(i-st+1);
}
return sol;
}
int main()
{
freopen("secv5.in", "r", stdin);
freopen("secv5.out", "w", stdout);
long long sol;
scanf("%d%d%d", &n, &a, &b);
for(int i=1; i<=n; ++i)
scanf("%u", &v[i]);
sol=rez(b) - rez(a-1);
printf("%lld\n", sol);
return 0;
}