Pagini recente » Cod sursa (job #2185059) | Cod sursa (job #1352677) | Cod sursa (job #1001764) | Cod sursa (job #1125416) | Cod sursa (job #222646)
Cod sursa(job #222646)
#include <cstdio>
using namespace std;
FILE *in,*out;
int n,k,a,b,i,aux,contor,j,q;
long sum[500007],x;
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",&x);sum[i]=sum[i-1]+x;
(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;
}