题意:基础的二维数组,注意 0 + lowbit(0)会陷入无限循环-----

之前做一道一维的一直tle,就是因为这个--------------------------

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include <cmath>
  5. #include<stack>
  6. #include<vector>
  7. #include<map>
  8. #include<set>
  9. #include<queue>
  10. #include<algorithm>
  11. using namespace std;
  12.  
  13. typedef long long LL;
  14. const int INF = (<<)-;
  15. const int mod=;
  16. const int maxn=;
  17.  
  18. int c[][];
  19. int n;
  20.  
  21. int lowbit(int x){ return x & (-x);}
  22.  
  23. int sum(int x,int y){
  24. int ret = ,y1;
  25. while(x > ){
  26. y1 = y;
  27. while( y1 > ){
  28. ret += c[x][y1];y1 -= lowbit(y1);
  29. }
  30. x-=lowbit(x);
  31. }
  32. return ret;
  33. }
  34.  
  35. void add(int x,int y,int d){
  36. int y1;
  37. while(x <= n){
  38. y1 = y;
  39. while(y1 <= n){
  40. c[x][y1] += d; y1 += lowbit(y1);
  41. }
  42. x += lowbit(x);
  43. }
  44. }
  45.  
  46. int main(){
  47. int cmd;
  48. while(scanf("%d %d",&cmd,&n) != EOF){
  49. memset(c,,sizeof(c));
  50. while(scanf("%d",&cmd) != EOF && cmd != ){
  51. if(cmd == ){
  52. int x,y,d;
  53. scanf("%d %d %d",&x,&y,&d);x++;y++;
  54. add(x,y,d);
  55. }
  56. else{
  57. int x,y,xx,yy;
  58. int ret = ;
  59. scanf("%d %d %d %d",&x,&y,&xx,&yy);
  60. x++;y++;xx++;yy++;
  61. ret = sum(xx,yy) - sum(x-,yy) - sum(xx,y-) + sum(x-,y-);
  62. printf("%d\n",ret);
  63. }
  64. }
  65. }
  66. return ;
  67. }

话说好几天没有写代码了的说啊----

加油↖(^ω^)↗

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. P2740 [USACO4.2]草地排水Drainage Ditches

    题目背景 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水系统来使贝茜的草地免除被大水淹没 ...

  2. Paper-[arXiv 1710.03144]Island Loss for Learning Discriminative Features in Facial Expression

    [arXiv 1710.03144]Island Loss for Learning Discriminative Features in Facial Expression ABSTRACT 作者在 ...

  3. 第十三章 Python并发编程

    并发编程之多进程 python中如果想要充分的利用多核CPU的资源,大部分情况需要使用多进程,python提供了multiprocessing multiprocessing模块用来开启子进程,并在子 ...

  4. Pyhton学习——Day9(阶段性练习)

    # 1.文件内容如下,标题为:姓名,性别,年纪,薪资## egon male 18 3000# alex male 38 30000# wupeiqi female 28 20000# yuanhao ...

  5. java web 初尝遇到的坑

    1. 配置 tomcat 7 + Dynamic web model version 3 发现写 web.xml 导致 tomcat 不能启动. 解决办法:tomcat 7 之后有两种配置 servl ...

  6. Python笔记27----时间解析

    1.将时间字符串解析成真正的时间 time.strptime http://www.runoob.com/python/att-time-strptime.html 代码: import time s ...

  7. [学习笔记] CS131 Computer Vision: Foundations and Applications:Lecture 4 像素和滤波器

    Background reading: Forsyth and Ponce, Computer Vision Chapter 7 Image sampling and quantization Typ ...

  8. apche本地测试,无法访问此网站

  9. POI 详细介绍

    Apache POI是一个开源的Java读写Excel.WORD等微软OLE2组件文档的项目.目前POI已经有了Ruby版本. 结构: HSSF - 提供读写Microsoft Excel XLS格式 ...

  10. MRv2 工作机制 、 公平调度器、MR压缩、边数据

    对于节点数超过 4000 的大型集群,前一节描述的 MapReduce 系统开始面临着扩展的瓶颈. 2010 年 Yahoo 的团队开始设计下一代的 MapReduce. (Yet Another R ...