Pagini recente » Cod sursa (job #989108) | Cod sursa (job #442659) | Cod sursa (job #2527637) | Cod sursa (job #193305) | Cod sursa (job #1706055)
#include <cstdio>
#include <algorithm>
#define MAXN (1<<20)
#define MAXBUF (1<<20)
FILE*fi,*fout;
using namespace std;
char buf[MAXBUF];
int vf1[MAXN+1],vf2[MAXN+1],vec[MAXN],pos=MAXBUF;
struct numar{
int poz;
long long val;
};
numar v[MAXN];
inline char nextch(){
if(pos==MAXBUF){
fread(buf,1,MAXBUF,fi);
pos=0;
}
return buf[pos++];
}
inline long long getnr(){
char a=nextch();
while(a<'0'||a>'9')
a=nextch();
long long nr=0;
while(a>='0'&&a<='9'){
nr=nr*10+a-'0';
a=nextch();
}
return nr;
}
bool cmp(numar a,numar b){
return (a.val<b.val);
}
int main(){
int n,l,u,i,j,nr,b,e1,e2,con1,con2;
long long nrsub,aux;
fi=fopen("secv5.in" ,"r");
fout=fopen("secv5.out" ,"w");
n=getnr();
l=getnr();
u=getnr();
for(i=0;i<n;i++){
v[i].val=getnr();
v[i].poz=i;
}
sort(v,v+n,cmp);
i=0;
nr=1;
while(i<n){
j=i;
aux=v[i].val;
while(j<n&&v[j].val==aux){
vec[v[j].poz]=nr;
j++;
}
nr++;
i=j;
}
e1=con1=0;
while(e1<n&&con1<l){
if(vf1[vec[e1]]==0)
con1++;
vf1[vec[e1]]++;
e1++;
}
e2=con2=0;
while(e2<n&&con2<=u){
if(vf2[vec[e2]]==0)
con2++;
vf2[vec[e2]]++;
e2++;
}
if(con2>u){
con2--;
vf2[vec[e2-1]]--;
e2--;
}
b=0;
nrsub=e2-e1+1;
while(b<n){
vf1[vec[b]]--;
if(vf1[vec[b]]==0)
con1--;
vf2[vec[b]]--;
if(vf2[vec[b]]==0)
con2--;
b++;
while(e1<n&&con1<l){
if(vf1[vec[e1]]==0)
con1++;
vf1[vec[e1]]++;
e1++;
}
while(e2<n&&con2<=u){
if(vf2[vec[e2]]==0)
con2++;
vf2[vec[e2]]++;
e2++;
}
if(con2>u){
con2--;
vf2[vec[e2-1]]--;
e2--;
}
if(con1==l)
nrsub=nrsub+(e2-e1+1);
}
fprintf(fout,"%lld" ,nrsub);
fclose(fi);
fclose(fout);
return 0;
}