Pagini recente » Cod sursa (job #2763062) | Cod sursa (job #1942286) | Cod sursa (job #2715444) | Cod sursa (job #117658) | Cod sursa (job #1762248)
#include <stdio.h>
#include <stdlib.h>
#define MOD 1079227
#define MAXN (1<<20)
#define h(x) (x%MOD)
unsigned int v[MAXN+1], val[2*MAXN+1], lista[2][MOD+1], next[2*MAXN+1], f[2*MAXN+1], m;
long long rasp;
inline void insert(int x, int ok){
int hash=h(x);
val[++m]=x;
f[m]=1;
next[m]=lista[ok][hash];
lista[ok][hash]=m;
}
inline int cauta(int x, int ok){
int poz, hash;
hash=h(x);
poz=lista[ok][hash];
while(poz && val[poz]!=x)
poz=next[poz];
return poz;
}
inline void deleteme(int x, int ok, int *point){
int poz, hash;
hash=h(x);
poz=lista[ok][hash];
if(val[poz]==x){
f[poz]--;
if(!f[poz]){
//lista[ok][hash]=next[poz];
(*point)--;
}
return;
}
while(next[poz] && val[next[poz]]!=x)
poz=next[poz];
if(val[next[poz]]==x){
f[next[poz]]--;
if(!f[next[poz]]){
(*point)--;
//next[poz]=next[next[poz]];
}
}
}
int main(){
int n, l, u, difl, difu, poz1, poz2, i, p;
FILE *fin, *fout;
fin=fopen("secv5.in", "r");
fout=fopen("secv5.out", "w");
fscanf(fin, "%d%d%d", &n, &l, &u);
for(i=1; i<=n; i++)
fscanf(fin, "%u", &v[i]);
difl=difu=poz1=poz2=0;
for(i=1; i<=n; i++){
while(difl<l && poz1<n){
poz1++;
p=cauta(v[poz1], 0);
if(!p){
insert(v[poz1], 0);
difl++;
}
else f[p]++;
}
while(difu<u && poz2<n){
poz2++;
p=cauta(v[poz2], 1);
if(!p){
insert(v[poz2], 1);
difu++;
}
else f[p]++;
}
while( difu==u && (p=cauta(v[poz2+1], 1))>0 ){
poz2++;
f[p]++;
}
if(difl==l)
rasp+=poz2-poz1+1;
deleteme(v[i], 0, &difl);
deleteme(v[i], 1, &difu);
}
fprintf(fout, "%lld\n", rasp);
fclose(fin);
fclose(fout);
return 0;
}