POJ 1195
来源:互联网 发布:在线c语言编译器 编辑:程序博客网 时间:2024/05/23 15:33
【题目分析】
二维树状数组。
【代码】
#include <cstdio>int t[1025][1025],n,opt;inline void add(int x,int y,int a){ for (int i=x;i<=n;i+=i&(-i)) for (int j=y;j<=n;j+=j&(-j)) t[i][j]+=a;}inline int getsum(int x,int y){ int ret=0; for (int i=x;i>=1;i-=i&(-i)) for (int j=y;j>=1;j-=j&(-j)) ret+=t[i][j]; return ret;}int main(){ scanf("%*d%d",&n); while (scanf("%d",&opt)!=EOF&&opt!=3) { if (opt==1) { int x,y,a; scanf("%d%d%d",&x,&y,&a); add(x+1,y+1,a); } if (opt==2) { int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); ++x1,++x2,++y1,++y2; printf("%d\n",getsum(x2,y2)-getsum(x2,y1-1)-getsum(x1-1,y2)+getsum(x1-1,y1-1)); } }}
0 0
- POJ 1195
- poj 1195
- POJ 1195
- poj 1195
- poj 1195
- poj 1195
- poj 1195
- poj 1195
- poj 1195
- POJ 1195
- poj-1195
- poj 1195
- poj 1195
- POJ 1195
- poj 1195
- 树状数组(poj 1195,poj 3321)
- POJ 1195 Mobile phones
- poj 1195 Mobile phones
- 树莓派安装中文字库和中文输入法
- 10-调用门(有参)实验
- Queue of Soldiers
- HDU1166-敌兵布阵
- 线性表的选择排序
- POJ 1195
- [Jquery]Cannot read property 'msie' of undefined
- UC/OS-II的中断和时钟
- java集合框架系列---Iterator和Enumeration比较
- Mongodb启动问题
- virtualenv的简单用法
- Inverted Multi-Index
- UVA 247 - Calling Circles(floyd判断包闭 ,dfs输出)
- vue.js视频教程,vue.js视频教程下载