Cod sursa(job #481835)

Utilizator bog29Antohi Bogdan bog29 Data 1 septembrie 2010 19:33:44
Problema Divk Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<fstream>
#include<vector>
#include<algorithm>
#define dmax 500003
#define nmax 200003
using namespace std;
ifstream in("divk.in");
ofstream out("divk.out");

long int sol;
long int n,a,b,k,s[dmax],v,r;

vector<long int>h[nmax];
vector<long int>::iterator it,ir;

int main()
{	long int i;
	in>>n>>k>>a>>b;
	
	h[0].push_back(0);
	for(i=1;i<=n;i++)
	{	in>>v;
		s[i]=s[i-1]+v;
		r=s[i]%k;
		h[r].push_back(i);
	}
	in.close();
	
	for(i=1;i<=n;i++)
	{	r=s[i]%k;
		if(!h[r].empty() )
		{	
			it=lower_bound(h[r].begin(),h[r].end(), i-b);
			ir=lower_bound(h[r].begin(),h[r].end(), i-a+1);
			sol+=(ir-it);
		}
	}
	
	out<<sol;
	
	out.close();
	return 0;
}