poj 1198 二维树状数组
来源:互联网 发布:php 明天时间戳 编辑:程序博客网 时间:2024/06/04 23:32
每次更新一个点,然后最后统计一个区间
很常规
AC代码如下:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int MAX_S = 1024 + 5;int sum[MAX_S][MAX_S];int statu, S;inline int lowbit( int x ){ return x&-x;}int getsum( int x, int y ){ int ans = 0; for( int i = x; i > 0; i -= lowbit( i ) ){ for( int j = y; j > 0; j -= lowbit( j ) ){ ans += sum[i][j]; } } return ans;}void updata( int x, int y, int val ){ for( int i = x; i <= S; i += lowbit( i ) ){ for( int j = y; j <= S; j += lowbit( j ) ){ sum[i][j] += val; } }}int main(){ while( scanf( "%d", &statu ) && statu != 3 ){ if( statu == 0 ){ scanf( "%d", &S ); memset( sum, 0, sizeof( sum ) ); }else if( statu == 1 ){ int temp1, temp2, temp3; scanf( "%d%d%d", &temp1, &temp2, &temp3 ); updata( temp1 + 1, temp2 + 1, temp3 ); }else{ int temp1, temp2, temp3, temp4; scanf( "%d%d%d%d", &temp1, &temp2, &temp3, &temp4 ); temp1++; temp2++; temp3++; temp4++; int ans = getsum( temp3, temp4 ); ans += getsum( temp1 - 1, temp2 - 1 ); ans -= getsum( temp1 - 1, temp4 ); ans -= getsum( temp3, temp2 - 1 ); printf( "%d\n", ans ); } } return 0;}
0 0
- poj 1198 二维树状数组
- poj 2155 二维树状数组 poj 1195 二维树状数组
- POJ 1195 二维树状数组
- POJ 2155 二维树状数组
- POj 2029 (二维树状数组)
- POJ 1195 二维树状数组
- POJ 1195 二维树状数组
- Poj 1195 二维树状数组
- POJ 1195 二维树状数组
- POJ 2155 二维树状数组
- POJ 1656 二维树状数组
- 【二维树状数组】POJ 1195
- poj 2155 二维树状数组
- POJ 1195 二维树状数组
- poj 2155 二维树状数组
- poj 1195 二维树状数组
- POJ 1195 二维树状数组
- poj 2155 二维树状数组
- Python学习笔记(二):循环
- The resource is not on the build path of a java project
- HTML中的表单
- Kolya and Tandem Repeat - CF#253 (Div. 2)B (443B) 哈希或水题
- 解决Toast重复弹出,Toast单例模式
- poj 1198 二维树状数组
- 虚拟化KVM的使用 - mouse without borders
- c编译错误--error:stray \357 in program及其引发的字符编码概述
- Borya and Hanabi - CF#253 (Div. 2)C (442A) 状压暴力枚举
- css span提示框 练习(不能用div)
- 电子商务网站测试经验总结
- python url请求 乱码 urllib.quote 中文
- UVA 10196 Morning Walk(欧拉回路)
- 从键盘接受一个字符串(String),并将其转换为字符型(char)