Pagini recente » Cod sursa (job #1355082) | Cod sursa (job #2104884) | Cod sursa (job #758222) | Cod sursa (job #1637586) | Cod sursa (job #1065278)
#include<cstdio>
#include<vector>
using namespace std;
const int NMAX = (1<<20)+5;
const int MOD = 100009;
unsigned int N,L,U,i,j,k,X,r,ok,Nr,Cnt,A,B,Dist,Ap[NMAX],Ap2[NMAX],Dist2,E[NMAX];
long long SOL;
vector<pair<int,int> > V[MOD];
int main()
{
freopen("secv5.in","r",stdin);
freopen("secv5.out","w",stdout);
scanf("%u%u%u",&N,&L,&U); A=U; B=L-1;
for(i=1,j=1,k=1;i<=N;i++)
{
scanf("%u",&X); r=X%MOD; ok=1;
for(vector<pair<int,int> >::iterator it=V[r].begin();it!=V[r].end();it++)
if(it->first==X) {ok=0; Nr=it->second; break;}
if(ok) V[r].push_back(make_pair(X,++Cnt)),Nr=Cnt;
E[i]=Nr;
Ap[Nr]++; if(Ap[Nr]==1) Dist++;
Ap2[Nr]++; if(Ap2[Nr]==1) Dist2++;
while(Dist>A)
{
j++; Ap[E[j-1]]--;
if(Ap[E[j-1]]==0) Dist--;
}
while(Dist2>B)
{
k++; Ap2[E[k-1]]--;
if(Ap2[E[k-1]]==0) Dist2--;
}
SOL+=i-j+1;
SOL-=i-k+1;
}
printf("%lld\n",SOL);
return 0;
}