fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int t;
  9. cin >> t;
  10.  
  11. while (t--) {
  12. int n, k;
  13. cin >> n >> k;
  14.  
  15. vector<long long> a(n), pre(n);
  16. for (int i = 0; i < n; i++) cin >> a[i];
  17.  
  18. pre[0] = a[0]%k;
  19. for (int i = 1; i < n; i++) pre[i] = (pre[i - 1] + a[i])%k;
  20.  
  21. vector<int> cnt(k);
  22. long long ans = 0;
  23.  
  24. for (int i = k; i < n; i++) {
  25. int j = i - k - 1;
  26. if (j < 0) cnt[0]++;
  27. else cnt[pre[j]]++;
  28. ans += cnt[pre[i]];
  29. }
  30.  
  31. cout << ans << '\n';
  32. }
  33. }
  34.  
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty