hdu2642 Stars 二维树状数组
来源:互联网 发布:门口的野蛮人 知乎 编辑:程序博客网 时间:2024/05/19 00:14
Problem:
给了一个矩阵,每次可以更新一个点的值,多次查询一个子矩阵的和。
Solution:
二维树状数组。
#include<cstdio>#include<iostream>#include<sstream>#include<cstdlib>#include<cmath>#include<cctype>#include<string>#include<cstring>#include<algorithm>#include<stack>#include<queue>#include<set>#include<map>#include<ctime>#include<vector>#include<fstream>#include<list>#include <iomanip>using namespace std;typedef long long ll;typedef unsigned long long ull;#define ms(s) memset(s,0,sizeof(s))const double PI = 3.141592653589;const int INF = 0x3fffffff;bool b[1010][1010];long long BI_tree[1010][1010];int nx, ny;inline int lowbit(int x) { return x & -x;}void update(int x, int y, int v) { for(int i = x; i <= nx; i += lowbit(i)) for(int j = y; j <= ny; j += lowbit(j)) BI_tree[i][j] += v;}long long query(int x, int y) { long long ans = 0; for(int i = x; i > 0; i -= lowbit(i)) for(int j = y; j > 0; j -= lowbit(j)) ans += BI_tree[i][j]; return ans;}int main() {// freopen("/Users/really/Documents/code/input","r",stdin); // freopen("/Users/really/Documents/code/output","w",stdout); ios::sync_with_stdio(false); int m; cin >> m; nx = ny = 1001; while(m--) { char c; int x, y, x1, y1; cin >> c; if(c == 'B') { cin >> x >> y; x++; y++; if(b[x][y] == false) { update(x, y, 1); b[x][y] = true; } } else if(c == 'D') { cin >> x >> y; x++; y++; if(b[x][y] == true) { update(x, y, -1); b[x][y] = false; } } else if(c == 'Q') { cin >> x >> x1 >> y >> y1; x++; y++; x1++; y1++; if(x1 < x) swap(x, x1); if(y1 < y) swap(y, y1); cout << query(x1, y1) - query(x-1, y1) - query(x1, y-1) + query(x-1, y-1) << endl; } } return 0;}
阅读全文
1 0
- HDU2642 Stars 二维树状数组
- HDU2642 Stars【二维树状数组】
- HDU2642 Stars 二维树状数组
- hdu2642 Stars 二维树状数组
- 树状数组(二维)例题 HDU2642——Stars
- 二维树状数组hdu2642
- hdu2642之二维树状数组
- hdu2642 二维树状组
- hduoj Stars 二维树状数组
- hdu2642二维树状数组单点更新+区间查询
- hdu2642-二维树状数组 单点更新 区间查询
- HDU2642(容斥定理+二维树状数组)
- hdu 2642stars(二维树状数组)
- HDU 2642 stars 二维树状数组
- hdu 2642 stars (二维树状数组)
- HDU 2642 Stars (二维树状数组)
- [hoj 2678]Stars[二维树状数组]
- HDU 2642 Stars(二维树状数组)
- ArrayList、Vector、HashMap、HashTable、HashSet的默认初始容量、加载因子、扩容增量
- RTAI API---Mailbox functions
- is_null,is_numeric
- 对doget和dopost区别的理解
- distinguish "list" & "array" in python
- hdu2642 Stars 二维树状数组
- 亚马逊说:你们是我见过最惨的一届new grad
- java引用传递和值传递的问题
- 02-线性结构3 Reversing Linked List
- 【git相关3】分支管理
- hashmap hashtable 的区别
- yum localinstall 解决本地rpm包的依赖问题
- RecyclerView使用ItemDecoration实现吸顶效果
- 【Ubuntu】 Ubuntu16.04系统美化