fork download
  1. #include <iostream>
  2. using namespace std;
  3. const long long INF = 105;
  4. long long arr[INF][INF][INF];
  5. long long amountArray[INF][INF][INF];
  6. int main() {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10. long long n,m,k;
  11. cin >> n >> m >> k;
  12. for(int i = 1 ; i <= n; i++){
  13. for(int j = 1 ; j <= m ; j++){
  14. for(int z = 1 ; z <= k ; z++){
  15. cin >> arr[i][j][z];
  16. }
  17. }
  18. }
  19. for(int i = 1 ; i <= n; i++){
  20. for(int j = 1; j <= m ; j++){
  21. amountArray[i][j][1] = amountArray[i-1][j][1] +
  22. amountArray[i][j-1][1] - amountArray[i-1][j-1][1] + arr[i][j][1];
  23. }
  24. }
  25. for(int i = 1 ; i <= m; i++){
  26. for(int j = 1; j <= k ; j++){
  27. amountArray[1][i][j] = amountArray[1][i-1][j] +
  28. amountArray[1][i][j-1] - amountArray[1][i-1][j-1] + arr[1][i][j];
  29. }
  30. }
  31. for(int i = 1 ; i <= n; i++){
  32. for(int j = 1; j <= k ; j++){
  33. amountArray[i][1][j] = amountArray[i-1][1][j] +
  34. amountArray[i][1][j-1] - amountArray[i-1][1][j-1] + arr[i][1][j];
  35. }
  36. }
  37.  
  38. for(int i = 2; i <= n; i++){
  39. for(int j = 2; j <= m ; j++){
  40. for(int z = 2; z <= k; z++){
  41. amountArray[i][j][z] = arr[i][j][z] +
  42. amountArray[i-1][j][z] + amountArray[i][j-1][z] -
  43. amountArray[i-1][j-1][z] + amountArray[i][j][z-1] -
  44. amountArray[i-1][j][z-1] - amountArray[i][j-1][z-1] +
  45. amountArray[i-1][j-1][z-1];
  46. }
  47. }
  48. }
  49. long long q;
  50. cin >> q;
  51. while(q--){
  52. long long x1, y1, z1, x2, y2, z2;
  53. cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
  54. x1--;
  55. y1--;
  56. z1--;
  57. cout << amountArray[x2][y2][z2] - amountArray[x2][y2][z1] -
  58. amountArray[x2][y1][z2] + amountArray[x2][y1][z1] -
  59. amountArray[x1][y2][z2] + amountArray[x1][y1][z2] +
  60. amountArray[x1][y2][z1] - amountArray[x1][y1][z1] << "\n";
  61. }
  62. return 0;
  63. }
Time limit exceeded #stdin #stdout 5s 33328KB
stdin
Standard input is empty
stdout
Standard output is empty