Cod sursa(job #3349537)

Utilizator pkseVlad Bondoc pkse Data 31 martie 2026 13:38:24
Problema Divk Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;

signed main() {
    ifstream cin("divk.in");
    ofstream cout("divk.out");
    
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, k, x, y; cin >> n >> k >> x >> y;
    
    vector <int> a(n + 1);
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
    }

    vector <int> s(k);
    int ans = 0;

    for (int i = 0; i < n; i ++) {
        a[i + 1] += a[i];
        if (i - x + 1 >= 0) {
            s[a[i - x + 1] % k] ++;
        }

        if (i - y + 1 >= 0) {
            s[a[i - y] % k] --;
        }

        ans += s[a[i] % k];
    }

    cout << ans << '\n';
}