hoj1640Mobile Phone
来源:互联网 发布:孙总定制机箱淘宝店 编辑:程序博客网 时间:2024/05/17 08:06
点击打开题目
这是一个典型的二维树状数组,也是模板题;
二维树状数组可以参考:点击打开链接
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAXN = 1024;int c[MAXN + 1][MAXN + 1];int k, s;int lowbit( int x ){return x & (-x);}void UFset(int x, int y, int data){for(int i = x; i <= s; i += lowbit(i))for(int j = y; j <= s; j += lowbit(j))c[i][j] += data;}int GetSum(int x, int y){int res = 0;for(int i = x; i > 0; i -= lowbit(i))for(int j = y; j > 0; j -= lowbit(j))res += c[i][j];return res;}int Querry(int x1, int y1, int x2, int y2){return GetSum(x2, y2) - GetSum(x1 - 1, y2) - GetSum(x2, y1 - 1) + GetSum(x1 - 1, y1 - 1);}int main(){while(scanf("%d", &k) != EOF){scanf("%d", &s);memset(c, 0, sizeof(c));while(scanf("%d", &k) == 1 && (k != 3)){if(k == 1){int a, b, val;scanf("%d %d %d", &a, &b, &val);UFset(a+1, b+1, val);}else if(k == 2){int x1, x2, y1, y2;scanf("%d %d %d %d", &x1, &y1, &x2, &y2);printf("%d\n",Querry(x1+1, y1+1, x2+1, y2+1));}}}return 0;}
- hoj1640Mobile Phone
- phone
- B-phone
- cell phone
- Phone Numbers
- windows phone
- Windows phone
- Phone Bills
- Phone Gap
- phone基本概念
- Phone List
- IP Phone
- phone相关
- phone 介绍
- Phone List
- Phone Number
- Phone Number
- Phone List
- VS2010编译错误:fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x
- 二进制形式中1出现的次数
- sql server 怎么记录最新插入的数据(没有自动增长列)?
- 随笔:下跪网游女婿,应当受到尊重
- 用宏定义加字符串运算为女朋友完成她没做好的程序,勿喷
- hoj1640Mobile Phone
- 将字符串改为小写
- [cpp 编译]Autotools笔记 翻译自autotools官方文档
- js数组复制
- N个数中,1出现的次数
- SVM对偶问题
- wineserver的创建到读取请求
- 贪心算法——有关区间的问题
- ubuntu使用wget和goagent结合