Pagini recente » Cod sursa (job #2494707) | Cod sursa (job #889308) | Cod sursa (job #1313281) | Cod sursa (job #2785543) | Cod sursa (job #2524780)
#include <map>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("divk.in");
ofstream cout("divk.out");
struct vallist{
int nr = 0, *arr = NULL, tmpiter = 0;
};
map<int, vallist> vals;
pair<int, int> tmp[500002];
int n, k, a, b, l[500001], ps[500001];
long long sequences = 0;
int main(){
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;
vals[ps[x]].nr++;
}
for(auto &i : vals)
i.second.arr = new int[i.second.nr];
for(int x = 1;x<=n;x++){
vals[ps[x]].arr[vals[ps[x]].tmpiter++] = x;
}
for(int x = 1;x<=n;x++){
if(vals.find(ps[x - 1]) == vals.end())
continue;
vallist * val_list = &vals[ps[x - 1]];
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;
}