fork(2) download
  1. var
  2. a:array[0..128,0..128,0..128] of int64;
  3. n,q,w,e,temp,x1,x2,y1,y2,z1,z2:longint;
  4.  
  5. function add(q,w,e,x:longint):longint;
  6. var
  7. z,c:longint;
  8. begin
  9. z:=w;
  10. c:=e;
  11. while q <= n do
  12. begin
  13. while z <= n do
  14. begin
  15. while c <= n do
  16. begin
  17. inc(a[q,z,c],x);
  18. c:=c or (c + 1);
  19. end;
  20. c:=e;
  21. z:=z or (z + 1);
  22. end;
  23. z:=w;
  24. q:=q or (q + 1);
  25. end;
  26. end;
  27.  
  28. function sum(q,w,e:longint):int64;
  29. var
  30. t:int64;
  31. begin
  32. t := 0;
  33. while q >= 0 do
  34. begin
  35. while w >= 0 do
  36. begin
  37. while e >= 0 do
  38. begin
  39. inc(t,a[q,w,e]);
  40. e:=(e and (e + 1)) - 1;
  41. end;
  42. w:=(w and (w + 1)) - 1;
  43. end;
  44. q:=(q and (q + 1)) - 1;
  45. end;
  46. sum:=t;
  47. end;
  48.  
  49. begin
  50. {assign(input,'stars.in');
  51.   reset(input);
  52.   assign(output,'stars.out');
  53.   rewrite(output);}
  54. read(n);
  55. read(q);
  56. while q<>3 do
  57. begin
  58. if q = 2 then
  59. begin
  60. temp:=0;
  61. read(x1,y1,z1,x2,y2,z2);
  62. inc(temp,+sum(x2 + 0,y2 + 0,z2 + 0));
  63. inc(temp,-sum(x1 - 1,y2 + 0,z2 + 0));
  64. inc(temp,-sum(x2 + 0,y1 - 1,z2 + 0));
  65. inc(temp,-sum(x2 + 0,y2 + 0,z1 - 1));
  66. inc(temp,+sum(x1 - 1,y1 - 1,z2 + 0));
  67. inc(temp,+sum(x1 - 1,y2 + 0,z1 - 1));
  68. inc(temp,+sum(x2 + 0,y1 - 1,z1 - 1));
  69. inc(temp,-sum(x1 - 1,y1 - 1,z1 - 1));
  70. writeln(temp);
  71. end
  72. else if q = 1 then
  73. begin
  74. read(x1,y1,z1,e);
  75. add(x1,y1,z1,e);
  76. end;
  77. read(q);
  78. end;
  79. end.
Success #stdin #stdout 0s 17048KB
stdin
2
2 1 1 1 1 1 1
1 0 0 0 1
1 0 1 0 3
2 0 0 0 0 0 0
2 0 0 0 0 1 0
1 0 1 0 -2
2 0 0 0 1 1 1
3
stdout
0
1
4
2