Mai intai trebuie sa te autentifici.
Cod sursa(job #134685)
Utilizator | Data | 12 februarie 2008 03:00:30 | |
---|---|---|---|
Problema | Secventa 5 | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.24 kb |
#include<stdio.h>
struct nod{unsigned long int vi;unsigned long int vf;nod *next;};
unsigned long int N,L,U,i,x[1050000],a,b,c,cc,bb,
f1[1050000],f2[1050000],y,li,vn,sol;
nod *p[200000],*q;
void pune();
int main()
{
FILE *f,*g;f=fopen("secv5.in","r");g=fopen("secv5.out","w");
fscanf(f,"%lu%lu%lu",&N,&L,&U);
for(i=1;i<=N;i++)
{ fscanf(f,"%lu",&y);
vn=y%199999;
q=p[vn];
while(q&&(q->vi!=y))q=q->next;
if(q)x[i]=q->vf;
else{li++;x[i]=li;pune();}
}
while(bb<L)
{ b++;
if(b>N) { fprintf(g,"%lu\n",sol);fcloseall();return 0;}
f1[x[b]]++;if(f1[x[b]]==1)bb++;
f2[x[b]]=f1[x[b]];
}
c=b;cc=bb;
while(cc<=U)
{ c++;
if(c>N) cc=U+1;
else { f2[x[c]]++;if(f2[x[c]]==1)cc++;}
}
for(;;)
{
sol+=c-b;
a++;
f1[x[a]]--;
if(f1[x[a]]==0) bb--;
f2[x[a]]--;
if(f2[x[a]]==0) cc--;
while(bb<L)
{ b++;
if(b>N) { fprintf(g,"%lu\n",sol);fcloseall();return 0;}
f1[x[b]]++;if(f1[x[b]]==1)bb++;
}
if(c<=N)
while(cc<=U)
{ c++;
if(c>N) { cc=U+1;c=N+1;}
else { f2[x[c]]++;if(f2[x[c]]==1)cc++;}
}
}
}
void pune()
{ nod *nou;
nou=new nod;
nou->vi=y;
nou->vf=li;
if(!p[vn]){nou->next=0;p[vn]=nou;return;}
nou->next=p[vn];p[vn]=nou;
}