Pagini recente » Cod sursa (job #2386649) | Cod sursa (job #359457) | Cod sursa (job #23928) | Cod sursa (job #1645835) | Cod sursa (job #1540063)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("divk.in");
ofstream fout("divk.out");
const int NMax = 5e5 + 5;
const int MMax = 1e5 + 5;
const int BMax = 1 << 10;
int n, k;
int v[NMax], Count[MMax];
long long int Sum[NMax];
inline long long int Solve(const int &x){
memset(Count, 0, sizeof(Count));
Count[0] = 1;
long long int sol = 0;
for(int i = x, j = 1; i <= n; i++, j++){
sol += Count[Sum[i] % k];
Count[Sum[j] % k]++;
}
return sol;
}
int pos = BMax - 1;
char Buffer[BMax];
inline void Read(int &x){
while(!isdigit(Buffer[pos])){
if(++pos == BMax){
fin.read(Buffer, BMax);
pos = 0;
}
}
x = 0;
while(isdigit(Buffer[pos])){
x = x * 10 + (Buffer[pos] - '0');
if(++pos == BMax){
fin.read(Buffer, BMax);
pos = 0;
}
}
}
int main(){
int a, b;
fin >> n >> k >> a >> b;
for(int i = 1; i <= n; i++){
fin >> v[i];
Sum[i] = Sum[i - 1] + v[i];
}
fout << Solve(a) - Solve(b + 1);
return 0;
}