Pagini recente » Cod sursa (job #2828651) | Cod sursa (job #2428119) | Cod sursa (job #1512454) | Cod sursa (job #950498) | Cod sursa (job #1149325)
#include <cstdio>
#include <vector>
#include <queue>
#include <fstream>
using namespace std;
ifstream fin("divk.in");
ofstream fout("divk.out");
int main(int argc, char *argv[]) {
int k, a, b, n;
fin >> n >> k >> a >> b;
vector<queue<int> > mod_0(k, queue<int>());
vector<queue<int> > mod_1(k, queue<int>());
mod_0[0].push(0);
int c = 0;
int ant = 0;
for (int i = 0; i < n; ++i) {
int t;
fin >> t;
int m = (ant + t) % k;
ant = m;
mod_0[m].push(i + 1);
while(!mod_1[m].empty() && i - mod_1[m].front() + 1 > b) {
mod_1[m].pop();
}
while (!mod_0[m].empty() && i - mod_0[m].front() + 1 >= a) {
mod_1[m].push(mod_0[m].front());
mod_0[m].pop();
}
while(!mod_1[m].empty() && i - mod_1[m].front() + 1 > b) {
mod_1[m].pop();
}
c = c + mod_1[m].size();
}
fout << c << endl;
fout.close();
return 0;
}