Pagini recente » Cod sursa (job #2476058) | Cod sursa (job #2238215) | Cod sursa (job #2109355) | Cod sursa (job #1353987) | Cod sursa (job #222645)
Cod sursa(job #222645)
#include <cstdio>
using namespace std;
FILE *in,*out;
int n,k,a,b,i,aux,contor,j,q;
long sum[500007],sir[500007];
struct rest
{int nr;int *fii;} div[100007];
int main()
{in=fopen("divk.in","r");
fscanf(in,"%d %d %d %d",&n,&k,&a,&b);
sum[0]=0; contor=0;
for(i=0;i<=k;i++) div[i].nr=0;
for(i=1;i<=n;i++)
{fscanf(in,"%ld",&sir[i]);sum[i]=sum[i-1]+sir[i];
(div[sum[i]%k].nr)++;aux=div[sum[i]%k].nr;
div[sum[i]%k].fii[aux]=i;
} fclose(in);
for(i=0;i<=k;i++)
for(j=1;j<=div[i].nr;j++)
for(q=j;q<=div[i].nr;q++)
{if(a<(div[i].fii[k]-div[i].fii[j]+1)&&(div[i].fii[k]-div[i].fii[j]+1)<b) contor++; }
out=fopen("divk.out","w");
fprintf(out,"%d",contor);
fclose(out);
return 0;
}