Advertisement
Guest User

Untitled

a guest
Apr 11th, 2015
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <string>
  6. #include <vector>
  7. #include <queue>
  8. #include <stack>
  9. #include <cmath>
  10. #include <ctime>
  11. #include <cstdio>
  12. #include <set>
  13. #include <map>
  14.  
  15. using namespace std;
  16.  
  17. #define pb push_back
  18. #define mp make_pair
  19. #define fs first
  20. #define sd second
  21.  
  22. #define inf 1000000007
  23. #define nmax 200010
  24. #define mmax 100010
  25. #define eps 1e-7
  26.  
  27. using namespace std;
  28.  
  29. int n, m, q, f;
  30. int X1, Y1, X2, Y2, w;
  31. long long d[4], t[4][1010][1010], ans;
  32.  
  33. void inc(int x, int y, long long w)
  34. {
  35. d[0] = w, d[1] = w * (1 - y), d[2] = w * (1 - x), d[3] = w * (1 - x) * (1 - y);
  36. for(int i = x; i <= n; i |= i + 1)
  37. for(int j = y; j <= m; j |= j + 1)
  38. {
  39. t[0][i][j] += d[0];
  40. t[1][i][j] += d[1];
  41. t[2][i][j] += d[2];
  42. t[3][i][j] += d[3];
  43. }
  44. }
  45.  
  46. long long get(int x, int y)
  47. {
  48. d[0] = d[1] = d[2] = d[3] = 0;
  49. for(int i = x; i > 0; i = (i & (i + 1)) - 1)
  50. for(int j = y; j > 0; j = (j & (j + 1)) - 1)
  51. {
  52. d[0] += t[0][i][j];
  53. d[1] += t[1][i][j];
  54. d[2] += t[2][i][j];
  55. d[3] += t[3][i][j];
  56. }
  57. return d[0] * x * y + d[1] * x + d[2] * y + d[3];
  58. }
  59.  
  60. int main()
  61. {
  62. //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  63. scanf("%d%d", &n, &m);
  64. scanf("%d", &q);
  65. while(q--)
  66. {
  67. scanf("%d%d%d%d%d", &f, &X1, &Y1, &X2, &Y2);
  68. if(f == 1)
  69. {
  70. scanf("%d", &w);
  71. inc(X1, Y1, w);
  72. inc(X2 + 1, Y2 + 1, w);
  73. inc(X2 + 1, Y1, -w);
  74. inc(X1, Y2 + 1, -w);
  75. }
  76. else
  77. printf("%I64d\n", get(X2, Y2) - get(X1 - 1, Y2) - get(X2, Y1 - 1) + get(X1 - 1, Y1 - 1));
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement