Cod sursa(job #3348263)

Utilizator RuxandraPro12_Metehau Ruxandra Maria RuxandraPro12_ Data 20 martie 2026 13:37:35
Problema Divk Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("divk.in");
ofstream fout("divk.out");

const int N_MAX = 5e5 + 5;

int n, k, a, b, sp[N_MAX], f[N_MAX], ans;

int main() {
    fin >> n >> k >> a >> b;
    for (int i = 1; i <= n; i++) {
        int x;
        fin >> x;
        sp[i] = (sp[i - 1] + x) % k;
        if (i >= a) {
            f[sp[i - a]]++;
            if (i > b)
                f[sp[i - b - 1]]--;
            ans += f[sp[i]];
        }
    }
    fout << ans << "\n";
    return 0;
}