Pagini recente » Cod sursa (job #2679216) | Cod sursa (job #500670) | Cod sursa (job #1044787) | Cod sursa (job #190707) | Cod sursa (job #2524775)
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("divk.in");
ofstream cout("divk.out");
struct vallist{
int nr = -1, *arr = NULL, val = -1;
vallist(int len, int v){
nr = len;
val = v;
arr = new int[len];
}
vallist(int v){
val = v;
}
};
vector<vallist> vals;
pair<int, int> tmp[500002];
int n, k, a, b, l[500001], ps[500001];
long long sequences = 0;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k>>a>>b;
for(int x = 1;x<=n;x++){
cin>>l[x];
l[x] %= k;
}
for(int x = 1;x<=n;x++){
ps[x] += ps[x - 1] + l[x];
ps[x] %= k;
}
{
for(int x = 1;x<=n;x++){
tmp[x] = pair<int, int>(ps[x], x);
}
sort(tmp + 1, tmp + n + 1);
tmp[n + 1] = {-1, -1};
int current = tmp[1].first, len = 1;
for(int x = 2;x<=(n+1);x++){
if(current != tmp[x].first){
vals.push_back(vallist(len, current));
for(int y = x - len, tmpi = 0;y != x;y++){
vals.back().arr[tmpi++] = tmp[y].second;
}
current = tmp[x].first;
len = 1;
}else len++;
}
}
for(int x = 1;x<=n;x++){
auto val_list = lower_bound(vals.begin(), vals.end(), vallist(ps[x - 1]), [](vallist a, vallist b){return a.val < b.val;});
if(val_list->val != ps[x - 1])
continue;
int LLEN = val_list->nr;
auto LIST = val_list->arr;
auto f = lower_bound(LIST, LIST + LLEN, x + a - 1), l = upper_bound(LIST, LIST + LLEN, x + b - 1);
if(f == (LIST + LLEN))
continue;
sequences += distance(f, l);
}
cout<<sequences<<endl;
}