Pagini recente » Cod sursa (job #1369492) | Cod sursa (job #40619) | Cod sursa (job #2978654) | Cod sursa (job #1991280) | Cod sursa (job #2408175)
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdio>
#define BUF_SIZE 4096
using namespace std;
ifstream f("divk.in");
ofstream g("divk.out");
int n,k,a,b,x,s;
vector <int> v[100005];
char buf[BUF_SIZE];
int pos = BUF_SIZE;
inline char getChar(FILE *f) {
if (pos == BUF_SIZE) {
fread(buf, 1, BUF_SIZE, f);
pos = 0;
}
return buf[pos++];
}
inline int read(FILE *f) {
int result = 0;
char c;
do {
c = getChar(f);
} while (!isdigit(c));
do {
result = 10 * result + c - '0';
c = getChar(f);
} while (isdigit(c));
return result;
}
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;
FILE *f=fopen("divk.in","r");
ofstream g("divk.out");
n=read(f);
k=read(f);
a=read(f);
b=read(f);
v[0].push_back(0);
for(i=1;i<=n;i++)
{
//f>>x;
x=read(f);
s=(s+x)%k;
v[s].push_back(i);
}
g<<Count(b)-Count(a-1);
return 0;
}