Cod sursa(job #3315212)

Utilizator hrib_the_slothAndreea Pasca hrib_the_sloth Data 13 octombrie 2025 01:18:58
Problema Divk Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <bits/stdc++.h>
using namespace std;
typedef long long i8;

int main() {
  // ifstream cin("divk.in");
  // ofstream cout("divk.out");
  int n, k, a, b;
  cin >> n >> k >> a >> b;
  vector<int> pfx(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> pfx[i];
    pfx[i] += pfx[i - 1];
    pfx[i] %= k;
  }
  vector<int> rest(k, 0);
  int res = 0;
  for (int i = a + 1; i <= n; i++) {
    int x = i - a;
    int y = i - b;
    if (y > 0) {
      rest[pfx[y - 1]]--;
    }
    rest[pfx[x]]++;
    res += rest[pfx[i]];
  }
  cout << res << "\n";
  return 0;
}