Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cstdlib>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <cmath>
- #include <ctime>
- #include <cstdio>
- #include <set>
- #include <map>
- using namespace std;
- #define pb push_back
- #define mp make_pair
- #define fs first
- #define sd second
- #define inf 1000000007
- #define nmax 200010
- #define mmax 100010
- #define eps 1e-7
- using namespace std;
- int n, m, q, f;
- int X1, Y1, X2, Y2, w;
- long long d[4], t[4][1010][1010], ans;
- void inc(int x, int y, long long w)
- {
- d[0] = w, d[1] = w * (1 - y), d[2] = w * (1 - x), d[3] = w * (1 - x) * (1 - y);
- for(int i = x; i <= n; i |= i + 1)
- for(int j = y; j <= m; j |= j + 1)
- {
- t[0][i][j] += d[0];
- t[1][i][j] += d[1];
- t[2][i][j] += d[2];
- t[3][i][j] += d[3];
- }
- }
- long long get(int x, int y)
- {
- d[0] = d[1] = d[2] = d[3] = 0;
- for(int i = x; i > 0; i = (i & (i + 1)) - 1)
- for(int j = y; j > 0; j = (j & (j + 1)) - 1)
- {
- d[0] += t[0][i][j];
- d[1] += t[1][i][j];
- d[2] += t[2][i][j];
- d[3] += t[3][i][j];
- }
- return d[0] * x * y + d[1] * x + d[2] * y + d[3];
- }
- int main()
- {
- //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
- scanf("%d%d", &n, &m);
- scanf("%d", &q);
- while(q--)
- {
- scanf("%d%d%d%d%d", &f, &X1, &Y1, &X2, &Y2);
- if(f == 1)
- {
- scanf("%d", &w);
- inc(X1, Y1, w);
- inc(X2 + 1, Y2 + 1, w);
- inc(X2 + 1, Y1, -w);
- inc(X1, Y2 + 1, -w);
- }
- else
- printf("%I64d\n", get(X2, Y2) - get(X1 - 1, Y2) - get(X2, Y1 - 1) + get(X1 - 1, Y1 - 1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement