Paste will expire never.
- #define _CRT_SECURE_NO_DEPRECATE
- #include <stdio.h>
- #include <vector>
- #include <algorithm>
- #include <stdlib.h>
- #include <ctime>
- #include <set>
- #include <map>
- #include <queue>
- #include <string>
- #include <math.h>
- #include <queue>
- #include <memory.h>
- #include <iostream>
- #include <stack>
- #include <complex>
- #include <list>
- using namespace std;
- void ASS(bool b)
- {
- if (!b)
- {
- ++*(int*)0;
- }
- }
- #define FOR(i, x) for (int i = 0; i < (int)(x); i++)
- #define CL(x) memset(x, 0, sizeof(x))
- #define CLX(x, y) memset(x, y, sizeof(x))
- #pragma comment(linker, "/STACK:106777216")
- const int N = 1024;
- struct RSQ {
- int a[N * 2][N * 2];
- RSQ()
- {
- memset(a, 0, sizeof(a));
- }
- void Build(int L, int R, int* ar) const
- {
- int k = 0;
- for (L += N, R += N; L < R; L >>= 1, R >>= 1) {
- if (L & 1)
- ar[k++] = L++;
- if (R & 1)
- ar[k++]= --R;
- }
- ar[k] = -1;
- }
- void Add(int posI, int posJ, int dVal)
- {
- for (int i = posI + N; i; i >>= 1)
- for (int j = posJ + N; j; j >>= 1)
- a[i][j] += dVal;
- }
- int Sum(int Lx, int Rx, int Ly, int Ry) const
- {
- int res = 0;
- int x[100];
- int y[100];
- Build(Lx, Rx, x);
- Build(Ly, Ry, y);
- for (int i = 0; x[i] != -1; i++)
- for (int j = 0; y[j] != -1; j++)
- res += a[x[i]][y[j]];
- return res;
- }
- };
- //struct invRSQ analogious
Editing is locked.