Pagini recente » Cod sursa (job #2330947) | Cod sursa (job #2472260) | Cod sursa (job #2964494) | Cod sursa (job #1179666) | Cod sursa (job #1149322)
#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<int> eq(n, 0);
vector<queue<int> > mod_0(k, queue<int>());
vector<queue<int> > mod_1(k, queue<int>());
mod_0[0].push(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();
}
eq[i] = mod_1[m].size();
}
int c = 0;
for (int i = 0; i < n; ++i) {
c = c + eq[i];
}
fout << c << endl;
fout.close();
return 0;
}