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 bb)
- {
- if (!bb)
- {
- ++*(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")
- typedef vector<int> vi;
- const int N = 1 << 8;
- struct RSQ2 {
- int a[N * 2][N * 2];
- RSQ2()
- {
- memset(a, 0, sizeof(a));
- }
- void Add(int posX, int posY, int dx)
- {
- for (int i = posX + N; i; i >>= 1)
- for (int j = posY + N; j; j >>= 1)
- a[i][j] += dx;
- }
- int Sum(int Lx, int Rx, int Ly, int Ry) const
- {
- int res = 0;
- for (Lx += N, Rx += N; Lx < Rx; Lx >>= 1, Rx >>= 1) {
- if (Lx & 1) {
- int tLy = Ly;
- int tRy = Ry;
- for (tLy += N, tRy += N; tLy < tRy; tLy >>= 1, tRy >>= 1) {
- if (tLy & 1)
- res += a[Lx][tLy++];
- if (tRy & 1)
- res += a[Lx][--tRy];
- }
- Lx++;
- }
- if (Rx & 1) {
- --Rx;
- int tLy = Ly;
- int tRy = Ry;
- for (tLy += N, tRy += N; tLy < tRy; tLy >>= 1, tRy >>= 1) {
- if (tLy & 1)
- res += a[Rx][tLy++];
- if (tRy & 1)
- res += a[Rx][--tRy];
- }
- }
- }
- return res;
- }
- };
- void Build(int L, int R, int *res) {
- int resc = 0;
- for (L += N, R += N; L < R; L >>= 1, R >>= 1) {
- if (L & 1)
- res[resc++] = L++;
- if (R & 1)
- res[resc++] = --R;
- }
- res[resc] = -1;
- }
- struct RSQ22 {
- int a[N * 2][N * 2];
- RSQ22()
- {
- memset(a, 0, sizeof(a));
- }
- void Add(int posX, int posY, int dx)
- {
- for (int i = posX + N; i; i >>= 1)
- for (int j = posY + N; j; j >>= 1)
- a[i][j] += dx;
- }
- int Sum(int Lx, int Rx, int Ly, int Ry) const
- {
- int res = 0;
- static int x[142];
- static int y[142];
- 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;
- }
- };
- int main()
- {
- return 0;
- }
Editing is locked.