Pagini recente » Cod sursa (job #3219788) | Cod sursa (job #464689) | Cod sursa (job #1434627) | Cod sursa (job #908465) | Cod sursa (job #2525321)
#include <deque>
#include <fstream>
#include <algorithm>
using namespace std;
//ifstream cin("divk.in");
ofstream cout("divk.out");
int n, k, a, b, l[500001];
pair<int, int> ps[500002];
pair<int, pair<int, int> > starts[500001];
long long sequences = 0;
int main() {
auto F = fopen("divk.in", "r");
fscanf(F, "%d%d%d%d", &n, &k, &a, &b);
a++;
b++;
for(int x = 1; x<=n; x++) {
fscanf(F, "%d", &l[x]);
l[x] %= k;
}
for(int x = 1; x<=n; x++) {
ps[x].first += ps[x - 1].first + l[x];
ps[x].first %= k;
ps[x].second = x;
}
sort(ps + 1, ps + n + 1);
ps[n + 1] = {-1, -1};
for(int x = 1, val = 0, st = 0;x<=(n+1);x++){
if(val != ps[x].first){
deque<int> close;
deque<int> far;
for(int i = st;i!=x;i++){
close.push_back(ps[i].second);
while(close.size() && ((ps[i].second - close.front() + 1) >= a)){
far.push_back(close.front());
close.pop_front();
}
while(far.size() && ((ps[i].second - far.front() + 1) > b)){
far.pop_front();
}
sequences += far.size();
}
val = ps[x].first;
st = x;
}
}
cout<<sequences<<endl;
}