Pagini recente » Cod sursa (job #2585899) | Cod sursa (job #1076363) | Cod sursa (job #294134) | Cod sursa (job #1075657) | Cod sursa (job #2408208)
#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) ;
}
*/
long long Count(int d)
{
int i,j,p;
long long nr=0;
for(p=0;p<k;++p)
{
j=0;
for(i=0;i<v[p].size();++i)
{
while(j<v[p].size() && v[p][j]-v[p][i]<=d)
{
j++;
}
nr=nr+j-i-1;
}
}
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;
}