fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main(){
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9. int n,k,c=0;
  10. cin>>n>>k;
  11. vector<int>v(n),p(n,0);
  12. for(int i=0;i<n;i++){
  13. cin>>v[i];
  14. if(i==0)p[0]=v[0];
  15. p[i]=p[i-1]+v[i];
  16. }
  17. unordered_map<int,int>mp;
  18. mp[0]=1;
  19. for(int i=0;i<n;i++){
  20. if(mp.find((p[i]%k-i%k-v[i]%k+k+1%k)%k)!=mp.end()){
  21. c+=mp[(p[i]%k-i%k-v[i]%k+k+1%k)%k];
  22. }
  23. mp[(p[i]%k-i%k-v[i]%k+k+1%k)%k]++;
  24. }
  25. cout<<c<<"\n";
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5320KB
stdin
4 4
1 3 2 4
stdout
2