题意:基础的二维数组,注意 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----

POJ 1195 Mobile phones【 二维树状数组 】的更多相关文章

  1. poj 1195 Mobile phones(二维树状数组)

    树状数组支持两种操作: Add(x, d)操作:   让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...

  2. POJ 1195:Mobile phones 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 16893   Accepted: 7789 De ...

  3. 【poj1195】Mobile phones(二维树状数组)

    题目链接:http://poj.org/problem?id=1195 [题意] 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y ...

  4. POJ 2155 Matrix【二维树状数组+YY(区间计数)】

    题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  5. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

  6. POJ 2155 Matrix (二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Descripti ...

  7. POJ 2155 Matrix 【二维树状数组】(二维单点查询经典题)

    <题目链接> 题目大意: 给出一个初始值全为0的矩阵,对其进行两个操作. 1.给出一个子矩阵的左上角和右上角坐标,这两个坐标所代表的矩阵内0变成1,1变成0. 2.查询某个坐标的点的值. ...

  8. POJ 2155 Matrix (二维树状数组)题解

    思路: 没想到二维树状数组和一维的比只差了一行,update单点更新,query求和 这里的函数用法和平时不一样,query直接算出来就是某点的值,怎么做到的呢? 我们在更新的时候不止更新一个点,而是 ...

  9. POJ 2155:Matrix 二维树状数组

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 21757   Accepted: 8141 Descripti ...

  10. POJ 2155 Matrix(二维树状数组)

    与以往不同的是,这个树状数组是二维的,仅此而已 #include <iostream> #include <cstdio> #include <cstring> # ...

随机推荐

  1. javascript中构造函数的说明

    1.1 构造函数是一个模板 构造函数,是一种函数,主要用来在创建对象时对 对象 进行初始化(即为对象成员变量赋初始值),并且总是与new运算符一起使用. 1.2 new 运算符 new运算符创建一个新 ...

  2. 快速新建一个纯净的java pom项目 project

    前期的java环境安装就不再阐述了使用步骤java -jar project-creator-0.1.jar projectName [war] 1> 比如你要创建一个项目名字叫 smile-o ...

  3. 『转』How to Think About Your Career

    开始工作的伊始,逐渐转载及阅读Medium上知名华裔设计师Julie Zhuo的文章,这是她在medium上的介绍:Product design VP @ Facebook. Lover of foo ...

  4. jsp基本内置标签

    <jsp:foward page="url"> <jsp:param value=" " name=" "/> &l ...

  5. servletconfig和servletcontext学习

    servletconfig java.lang.String getInitParameter(java.lang.String name)  //根据参数名获取参数值 java.util.Enume ...

  6. C编译时`true' undeclared (first use in this function)

    在编译C语言时有时会遇到这样的错误提示: 'true' undeclared (first use in this function) or `false' undeclared (first use ...

  7. js(Mandango:壮汉专用,电影院划位工具)

    Mandango:壮汉专用,电影院划位工具 <body onload="initSeats();"> <div style="margin-top:75 ...

  8. [NOIP2004提高组]虫食算

    题目:洛谷P1092.codevs1064.Vijos P1099. 题目大意:给你一个$n$进制.每个数都是$n$位的三个数a,b,c,这些数的数位由字母表示(共$n$个字母,从‘A’开始),所有数 ...

  9. BZOJ 4817 [SDOI2017]树点涂色 (LCT+线段树维护dfs序)

    题目大意:略 涂色方式明显符合$LCT$里$access$操作的性质,相同颜色的节点在一条深度递增的链上 用$LCT$维护一个树上集合就好 因为它维护了树上集合,所以它别的啥都干不了了 发现树是静态的 ...

  10. adb 相关问题总结

    1. adb shell权限问题$ su //root权限来启动adb server$ adb kill-server && adb start-server* daemon not ...