fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n,q,c; cin>>n>>q>>c;
  7. int dp[c+1][101][101]={0};
  8. // Initialize all time layers to 0
  9. // for(int t=0;t<=c;t++){
  10. // for(int x=0;x<=100;x++){
  11. // for(int y=0;y<=100;y++){
  12. // dp[t][x][y]=0;
  13. // }
  14. // }
  15. // }
  16.  
  17.  
  18. while(n--){
  19. int x,y,s; cin>>x>>y>>s;
  20. for(int t=0;t<=c;t++){
  21. dp[t][x][y]+=(s+t)%(c+1);
  22. }
  23. }
  24.  
  25. for(int t=0;t<=c;t++){
  26. for(int x=1;x<=100;x++){
  27. for(int y=1;y<=100;y++){
  28. dp[t][x][y]+=dp[t][x-1][y]+dp[t][x][y-1]-dp[t][x-1][y-1];
  29. }
  30. }
  31. }
  32. while(q--){
  33. int t,x1,y1,x2,y2;
  34. cin>>t>>x1>>y1>>x2>>y2;
  35. t=t%(c+1);
  36. cout<<dp[t][x2][y2]+dp[t][x1-1][y1-1]-dp[t][x1-1][y2]-dp[t][x2][y1-1]<<endl;
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5280KB
stdin
2 3 3
1 1 1
3 2 0
2 1 1 2 2
0 2 1 4 5
5 1 1 5 5
stdout
3
0
3