Pagini recente » Cod sursa (job #1022850) | Cod sursa (job #485222) | Cod sursa (job #1948907) | Cod sursa (job #2581056) | Cod sursa (job #1481540)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
const int NMAX=(1<<20)+5;
int n,L,U,a[NMAX],AIB[NMAX];
long long sol;
map<int,int>M;
inline int zeros(int x)
{
return x^(x&(x-1));
}
inline void Update(int poz,int val)
{
for (int i=poz;i<=n;i+=zeros(i)) AIB[i]+=val;
}
inline int Query(int poz)
{
int pw,rez=0,cnt=0;
if (poz==0) return 0;
for (pw=20;pw>=0;pw--)
if ((rez+(1<<pw))<=n && (cnt+AIB[rez+(1<<pw)])<poz)
{
rez+=1<<pw;
cnt+=AIB[rez];
}
rez++;
return rez;
}
int main()
{
int i,cnt=0;
fin>>n>>L>>U;
for (i=1;i<=n;i++) fin>>a[i];
for (i=1;i<=n;i++)
{
Update(i,1);
if (M.find(a[i])!=M.end()) Update(M[a[i]],-1);
else cnt++;
M[a[i]]=i;
if (cnt>=L) sol+=Query(cnt-L+1)-Query(max(0,cnt-U));
}
fout<<sol<<"\n";
return 0;
}