Pagini recente » Cod sursa (job #2732629) | Cod sursa (job #546400) | Cod sursa (job #2800280) | Cod sursa (job #1368588) | Cod sursa (job #1252492)
# include <cstdio>
# include <vector>
# define LL long long
# define MOD 666013
# define N (1<<20)+5
using namespace std;
bool ok;
vector <pair <int, int> > h[MOD];
vector <pair <int, int> > :: iterator it;
int distincte=0;
int n,l,u,a[N],i;
inline void sterge(int x)
{
int poz=x%MOD;
for(it=h[poz].begin(); it!=h[poz].end(); ++it)
if(it->first==x)
{
--it->second;
if(!it->second) distincte--;
}
}
inline void adauga(int x)
{
int poz=x%MOD;
ok=false;
for(it=h[poz].begin(); it!=h[poz].end(); ++it)
if(it->first==x)
{
++it->second;
ok=true;
}
if(!ok)
{
h[poz].push_back(make_pair(x,1));
distincte++;
}
}
inline LL nr(int x)
{
int i,st,dr;
for(i=0; i<MOD; ++i)
h[i].clear();
long long ans=0;
st=dr=1;
ans=distincte=0;
while(dr<=n)
{
adauga(a[dr]);
while(distincte>x)
{
sterge(a[st]);
st++;
}
ans+=(LL) dr-st+1;
dr++;
}
return ans;
}
int main()
{
freopen("secv5.in", "r", stdin);
freopen("secv5.out", "w", stdout);
scanf("%d %d %d\n", &n, &l, &u);
for(i=1; i<=n; ++i)
scanf("%d", a+i);
long long solutie=nr(u);
solutie-=nr(l-1);
printf("%lld\n", solutie);
fclose(stdin);
fclose(stdout);
return 0;
}