标签:现在 div set namespace 手机 cto == phone cst
有一个正方形游戏背包,大小为S*S(1<=S<=1024)。含有很多小格子,小格子编号从0开始,直到S-1。每一个格子里有一定数量的物品,同时每一个格子的物品里的数目也是不断变化的,现在要一边进行修改某些单位格子内的物品的数目,同时也要询问某些区域的手机数目。 数据保证每个格子内物品数目一直在int范围内,查询的格子内的物品数目也在int范围内
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<cstring> #include<stdio.h> #include<algorithm> #include<map> #include<queue> #include<set> #include <sstream> #include<vector> #include<cmath> #include<stack> #include<time.h> #include<ctime> using namespace std; #define inf 1<<30 #define eps 1e-7 #define LD long double #define LL long long #define maxn 100000005 int a[2005][2005] = {}; int c[2005][2005] = {}; int n; int lowbit(int m) { return m & (-m); } void add(int x, int y, int val) { a[x][y] += val; for (int i = x; i <= n; i += lowbit(i)) { for (int j = y; j <= n; j += lowbit(j)) { c[i][j] += val; } } } LL query(int x, int y) { LL ans = 0; for (int i = x; i>0; i -= lowbit(i)) { for (int j = y; j>0; j -= lowbit(j)) { ans += c[i][j]; } } return ans; } int main() { int T; while (~scanf("%d", &T)&&T!=3) { if (T == 0) { scanf("%d", &n); } else if (T == 1) { int q, w, e; scanf("%d%d%d", &q, &w, &e); q++; w++; add(q, w, e); } else if (T == 2) { int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); x1++; x2++; y1++; y2++; LL sum = 0; sum = query(x2, y2) - query(x1 - 1, y2) - query(x2, y1 - 1) + query(x1 - 1, y1 - 1); printf("%lld\n", sum); } } }
Mobile phones(二维树状数组) POJ - 1195
标签:现在 div set namespace 手机 cto == phone cst
原文地址:https://www.cnblogs.com/whhh/p/13381876.html