Cod sursa(job #504003)

Utilizator mgntMarius B mgnt Data 26 noiembrie 2010 09:16:03
Problema Divk Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>
using namespace std;

typedef long long int lli;
int const maxn=500*1000,maxk=100*1000;;
int S[maxn];
lli C[maxk];

int main()
{	ifstream is("divk.in");
	ofstream os("divk.out");
	int N,K,A,B,i;is>>N>>K>>A>>B;
	lli s=0;
	for(i=0;N>i;++i){is>>S[i];}S[0]%=K;
	for(i=1;N>i;++i){S[i]=(S[i-1]+S[i])%K;}
	for(i=0;K>i;++i){C[i]=0;}
	if(0==S[A-1]){++s;}
	for(i=A;B>=i;++i)
	{	++C[S[i-A]];
		s+=C[S[i]];
	}
	for(i=B+1;N>i;++i)
	{	--C[S[i-B-1]];
		++C[S[i-A]];
		s+=C[S[i]];
	}
	os<<s<<endl;
	return 0;
}