POJ 1195 Mobile phones【 二维树状数组 】
2024-10-01 13:24:48
题意:基础的二维数组,注意 0 + lowbit(0)会陷入无限循环-----
之前做一道一维的一直tle,就是因为这个--------------------------
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int c[][];
int n; int lowbit(int x){ return x & (-x);} int sum(int x,int y){
int ret = ,y1;
while(x > ){
y1 = y;
while( y1 > ){
ret += c[x][y1];y1 -= lowbit(y1);
}
x-=lowbit(x);
}
return ret;
} void add(int x,int y,int d){
int y1;
while(x <= n){
y1 = y;
while(y1 <= n){
c[x][y1] += d; y1 += lowbit(y1);
}
x += lowbit(x);
}
} int main(){
int cmd;
while(scanf("%d %d",&cmd,&n) != EOF){
memset(c,,sizeof(c));
while(scanf("%d",&cmd) != EOF && cmd != ){
if(cmd == ){
int x,y,d;
scanf("%d %d %d",&x,&y,&d);x++;y++;
add(x,y,d);
}
else{
int x,y,xx,yy;
int ret = ;
scanf("%d %d %d %d",&x,&y,&xx,&yy);
x++;y++;xx++;yy++;
ret = sum(xx,yy) - sum(x-,yy) - sum(xx,y-) + sum(x-,y-);
printf("%d\n",ret);
}
}
}
return ;
}
话说好几天没有写代码了的说啊----
加油↖(^ω^)↗
goooooooooooooooooo----
最新文章
- 使用angular.bootstrap() 完成模块的手动加载
- jquery怎么获取radio选中的值
- 在线音乐网站【03】Part one 功能实现
- 【Pro ASP.NET MVC 3 Framework】.学习笔记.8.SportsStore:管理
- 55.ERROR:Place:1136 - This design contains a global buffer instance…… non-clock load pins off chip
- Cassandra1.2文档学习(1)——Cassandra基本说明
- Win7新建ftp快捷方式(原XP网上邻居中客户端图标)
- 向着DJANGO奔跑!
- HA高可用的搭建
- perl学习(1) 入门
- 使用hexo搭建github博客
- app与后台交互之间的几种安全认证机制
- MySQL优化三(InnoDB优化)
- Java servlet ajax
- 点评阿里JAVA手册之MySQL数据库 (建表规约、索引规约、SQL语句、ORM映射)
- (cljs/run-at (JSVM. :all) ";一次说白DataType、Record和Protocol";)
- python学习之数字
- 微软Azure云计算服务主导全球
- C#/.NET基于Topshelf创建Windows服务程序及服务的安装和卸载(极速,简洁)
- Java 使用blob对H5视频播放进行加密《java视频加密》