二维树状数组板子题。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<vector>
  8. using namespace std;
  9. #define mem(a,b) memset(a,b,sizeof(a))
  10. #define ll long long
  11. #define inf 1000000000
  12. #define maxn 40000
  13. #define eps 1e-12
  14. #define mod 1000000007
  15. #define N 3005
  16. inline int read()
  17. {
  18. int x=,f=;char ch=getchar();
  19. while(ch<''||ch>'') {if(ch=='-') f=-;ch=getchar();}
  20. while(ch>=''&&ch<='') {x=*x+ch-'';ch=getchar();}
  21. return x*f;
  22. }
  23. int c[N][N],n;
  24. int lowbit(int i)
  25. {
  26. return i&(-i);
  27. }
  28. int sum(int x,int y)
  29. {
  30. int ret=;
  31. for(int i=x;i>;i-=lowbit(i))
  32. {
  33. for(int j=y;j>;j-=lowbit(j))
  34. ret+=c[i][j];
  35. }
  36. return ret;
  37. }
  38. void add(int x,int y,int d)
  39. {
  40. for(int i=x;i<=n;i+=lowbit(i))
  41. for(int j=y;j<=n;j+=lowbit(j))
  42. {
  43. c[i][j]+=d;
  44. }
  45. }
  46. int main()
  47. {
  48. int k,op,x,y,i,j;
  49. while(~scanf("%d%d",&i,&n))
  50. {
  51. mem(c,);
  52. while()
  53. {
  54. op=read();
  55. if(op==) break;
  56. if(op==) {
  57. x=read();y=read();k=read();
  58. add(x+,y+,k);
  59. }
  60. else{
  61. int l,b,r,t;
  62. l=read();b=read();r=read();t=read();
  63. l++;b++;r++;t++;
  64. printf("%d\n",sum(r,t)-sum(r,b-)-sum(l-,t)+sum(l-,b-));
  65. }
  66. }
  67. }
  68. return ;
  69. }

POJ1195Mobile phones的更多相关文章

  1. POJ1195--Mobile phones(基础二维BIT)

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  2. POJ1195Mobile phones (从二维树状数组到cdq分治)

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  3. poj1195Mobile phones(二维树状数组)

    http://poj.org/problem?id=1195 模版题 i写成k了 找了一个多小时没找出来.. #include <iostream> #include<cstring ...

  4. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  5. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

  6. POJ 1195 Mobile phones(二维树状数组)

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  7. Deal with Android phones with pattern lock on

    Yesterday my colleague asked me for help...She has two android phones , one is hTC and the other is ...

  8. C. Mobile phones

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  9. 【POJ1195】【二维树状数组】Mobile phones

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

随机推荐

  1. CentOS---JDK安装与配置

    1.先查看一下CentOS中存在的jdk安装包信息 # rpm -qa | grep java 查看CentOS安装的jdk版本 #java -version 2.分别执行以下命令将所有相关包都删除 ...

  2. LeetCode948-令牌放置

    问题:令牌放置 你的初始能量为 P,初始分数为 0,只有一包令牌. 令牌的值为 token[i],每个令牌最多只能使用一次,可能的两种使用方法如下: 如果你至少有 token[i] 点能量,可以将令牌 ...

  3. LigerUI 快速开发UI框架 链接

    LigerUI 快速开发UI框架 http://www.ligerui.com/ jQuery ligerUI 中文官方网站 http://www.ligerui.com/demo.html

  4. ecshop里提出来的js常用函数

    目录 Utils.js jquery.listTable.js 使用例子: ecshop里提出来的js常用函数 Utils.js /* $Id : utils.js 5052 2007-02-03 1 ...

  5. 如何将emoji表情存放到mysql数据库中

    昨晚在爬取猫眼电影评论时在将评论信息插入到数据库中时出现问题,总是在插入一条数据时就会报错: 看着应该时字符编码的问题,比如新建的数据库新建的表,默认字符编码是:Latin1, 这种编码是无法插入中文 ...

  6. 动态规划:HDU2844-Coins(多重背包的二进制优化)

    Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  7. hadoop启动时权限不足

    之前在使用时的没用去懂.ssh,后来因为一些情况直接将其权限修改为777. 第一位7等于4+2+1,所以就是rwx,所有者有读取.写入.执行的权限:第二位7也是4+2+1,rwx,同组用户具有读取.写 ...

  8. 笔记-python-反射

    笔记-python-反射 1. 反射 在很多地方看到自省和反射,很晕菜,整理了一下相关文档,加深了理解. 自省和反射其实说的是一件事,核心操作是根据输入去对象(模块)中调用(查找/获取/删除/添加)成 ...

  9. 用私有构造器或者枚举类型强化Singleton属性

    1.Singleton指仅仅被实例化一次的类.Singleton通常被用来代表那些本质上唯一的系统组件,如窗口管理器或者文件系统.使类称为Singleton会使它的客户端调试变的十分困难,因为无法给S ...

  10. Python之print函数详解

    输出的 print 函数总结: 1. 字符串和数值类型可以直接输出 >>> print(1) 1 >>> print("Hello World" ...