[Vijos1512] SuperBrother打鼹鼠 (二维树状数组)
2017-05-02 18:19
776 查看
直接搞就行。
注意下表re从零开始,而树状数组搞不了0,所以统一增加一个偏移量1.
(话说数据随机是什么鬼?)
# include <iostream> # include <cstdio> # include <cstring> # include <string> # include <cmath> # include <vector> # include <map> # include <queue> # include <cstdlib> # define MAXN 1100 using namespace std; inline int get_num() { int k = 0, f = 1; char c = getchar(); for(; !isdigit(c); c = getchar()) if(c == '-') f = -1; for(; isdigit(c); c = getchar()) k = k * 10 + c - '0'; return k * f; } int n; int c[MAXN][MAXN]; inline int lowbit(int x) { return x & -x; } inline void add(int x, int y, int k) { int i, j; for(i = x; i <= n; i += lowbit(i)) for(j = y; j <= n; j += lowbit(j)) c[i][j] += k; } inline int query(int x, int y) { int i, j, ans = 0; for(i = x; i; i -= lowbit(i)) for(j = y; j; j -= lowbit(j)) ans += c[i][j]; return ans; } int main() { int i, x, y, k, x1, x2, y1, y2, m; n = get_num() + 1; while(1) { m = get_num(); if(m == 3) break; if(m == 1) { x = get_num() + 1; y = get_num() + 1; k = get_num(); add(x, y, k); } else { x1 = get_num() + 1; y1 = get_num() + 1; x2 = get_num() + 1; y2 = get_num() + 1; printf("%d\n", query(x2, y2) - query(x1 - 1, y2) - query(x2, y1 - 1) + query(x1 - 1, y1 - 1)); } } return 0; }View Code
相关文章推荐
- vijos-1512 SuperBrother打鼹鼠(二维树状数组)
- VIJOS 1512SuperBrother打鼹鼠(二维BIT)
- 树状数组训练题2:SuperBrother打鼹鼠(vijos1512)
- 二维树状数组——SuperBrother打鼹鼠(Vijos1512)
- [Vijos 1512] SuperBrother打鼹鼠
- f697 树状数组-vijos1512SuperBrother打鼹鼠
- Vijos 1512 SuperBrother打鼹鼠
- POJ 1195 Mobile phones(二维树状数组)
- hdu 2642 Stars(二维树状数组)
- HDU 1892 See you~(二维树状数组)
- POJ 1195 Mobile phones(二维树状数组)
- HDUOJ---2642Stars(二维树状数组)
- 二维线段树(二维树状数组)poj2155
- poj 2155 二维树状数组
- Light OJ 1266(二维树状数组)
- POJ 2155 Matrix (二维树状数组)
- POJ1195——Mobile phones(二维树状数组)
- POJ 1195 Mobile phones (二维树状数组)
- hdu1081 DP类最大子段和(二维压缩+前缀和数组/树状数组计数)
- POJ 1195 Mobile phones(二维树状数组)