Pagini recente » Cod sursa (job #224786) | Cod sursa (job #1346488) | Cod sursa (job #3168311) | Cod sursa (job #2119222) | Cod sursa (job #2408172)
#include <iostream>
#include <fstream>
#include <vector>
# define verf ++poz == hg ? f.read (ch, hg), poz = 0 : 0
using namespace std;
ifstream f("divk.in");
ofstream g("divk.out");
int n,k,a,b,x,poz,s;
vector <int> v[100005];
const int hg = 1 << 13;
char ch[hg];
inline void cit ( int &x ) {
if (ch[0] == '\0') f.read (ch, hg) ;
else for (; ch[poz] < '0' || ch[poz] > '9' ; verf) ;
for (x = 0 ; ch[poz] >= '0' && ch[poz] <= '9' ; x = x * 10 + ch[poz] - '0', verf) ;
}
int Count(int d)
{
int i,j,p,nr;
nr=0;
for(p=0;p<k;p++)
{
for(i=0;i<v[p].size();i++)
{
j=i+1;
while(j<v[p].size() && v[p][j]-v[p][i]<=d)
{
nr++;
j++;
}
}
}
return nr;
}
int main()
{
int i;
//f>>n>>k>>a>>b;
cit(n);
cit(k);
cit(a);
cit(b);
v[0].push_back(0);
for(i=1;i<=n;i++)
{
//f>>x;
cit(x);
s=(s+x)%k;
v[s].push_back(i);
}
g<<Count(b)-Count(a-1);
return 0;
}