[POJ 1195] Mobile phones · 树状数组
来源:互联网 发布:js解析xml文件的作用 编辑:程序博客网 时间:2024/06/15 06:23
二维树状数组模板,不过注意要用读入优化。
#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;#define lowbit( x ) (( x ) & ( -x ))const int N = 1025 ;int n,f[N][N],x1,y1,x2,y2,c,p;void edit( int x , int y , int c ) {for (int i = x ; i <= n ; i += lowbit(i) )for (int j = y ; j <= n ; j += lowbit(j) )f[i][j] += c ;return ;}int sum( int x , int y ) {int ans = 0 ;for (int i = x ; i ; i -= lowbit( i ) )for (int j = y ; j ; j -= lowbit( j ) )ans += f[i][j] ;return ans ;}int get() {int p = 0 , t = 1 ; char x = getchar() ;while ( x < '0' || x > '9' ) {if ( x == '-' ) t = -1 ;x = getchar() ;}while ( x >= '0' && x <= '9' )p = p * 10 + x - '0' ,x = getchar() ;return p * t ;}int main() {getchar() ; n = get() ;p = get() ;while ( p != 3 ) {if ( p == 1 ) {x1 = get() ; y1 = get() ; c = get() ;x1 ++ ; y1 ++ ;edit( x1 , y1 , c ) ;}else {x1 = get() ; y1 = get() ; x2 = get() ; y2 = get() ;x1 ++ ; y1 ++ ; x2 ++ ; y2 ++ ;printf("%d\n" , sum( x2 , y2 ) + sum ( x1 - 1 , y1 - 1 ) - sum( x2 , y1 - 1 ) - sum( x1 - 1 , y2 ) );}p = get() ;}return 0;}
0 0
- [POJ 1195] Mobile phones · 树状数组
- POJ 1195 Mobile phones 二维树状数组
- POJ 1195 Mobile phones【二维树状数组】
- POJ 1195 Mobile phones 二维树状数组
- poj 1195 Mobile phones 二维树状数组
- poj 1195 Mobile phones(树状数组)
- POJ 1195 Mobile phones 二维树状数组
- poj 1195 Mobile phones +二维树状数组
- POJ 1195 Mobile phones 二维树状数组
- Mobile Phones poj 1195--二维树状数组
- POJ 1195 Mobile phones【二维树状数组】
- POJ 1195 Mobile phones(二维树状数组)
- poj 1195 - Mobile phones(树状数组)
- POJ 1195 Mobile phones(二维树状数组)
- poj - 1195 - Mobile phones(树状数组)
- [树状数组]POJ 1195 Mobile phones
- POJ 1195 Mobile phones(二维树状数组)
- poj 1195 mobile phones 二维树状数组
- 低头族,Look Up!
- Friend
- 二维高斯模糊和可分离核形式的快速实现
- 正则表达式与String类
- Android系统基本框架结构[续]
- [POJ 1195] Mobile phones · 树状数组
- Redis中key-value实现
- C++刷题——2713: 函数---求x的y次方
- 递归函数详解
- 【ThinkingInJava】54、对List操作中本质的部分进行测试还有Queue中的操作测试性能比较
- Flipping Parentheses
- 猫猫学iOS(四十九)多线程网络之线程的创建NSThreand
- 破解office13VOL
- Web端服务器推送技术原理分析及dwr框架简单的使用