Pagini recente » Cod sursa (job #848661) | Cod sursa (job #985409) | Cod sursa (job #25175) | Cod sursa (job #1736855) | Cod sursa (job #1481546)
#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,AIB[NMAX];
long long sol,a[NMAX];
unordered_map<long long,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;
}