时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

You are given an N × N matrix. At the beginning every element is 0. Write a program supporting 2 operations:

1. Add x y value: Add value to the element Axy. (Subscripts starts from 0

2. Sum x1 y1 x2 y2: Return the sum of every element Axy for x1 ≤ x ≤ x2y1 ≤ y ≤ y2.

输入

The first line contains 2 integers N and M, the size of the matrix and the number of operations.

Each of the following M line contains an operation.

1 ≤ N ≤ 1000, 1 ≤ M ≤ 100000

For each Add operation: 0 ≤ x < N, 0 ≤ y < N, -1000000 ≤ value ≤ 1000000

For each Sum operation: 0 ≤ x1 ≤ x2 < N, 0 ≤ y1 ≤ y2 < N

输出

For each Sum operation output a non-negative number denoting the sum modulo 109+7.

样例输入
  1. 5 8
  2. Add 0 0 1
  3. Sum 0 0 1 1
  4. Add 1 1 1
  5. Sum 0 0 1 1
  6. Add 2 2 1
  7. Add 3 3 1
  8. Add 4 4 -1
  9. Sum 0 0 4 4
样例输出
  1. 1
  2. 2
  3. 3
  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<iostream>
  4. #include<algorithm>
  5. #include<cstring>
  6. using namespace std;
  7. int n,c[][];
  8. const int Mod=1e9+;
  9. int lowbit(int x)
  10. {
  11. return x&(-x);
  12. }
  13. void add(int x,int y,int val)
  14. {
  15. for(int i=x;i<=n;i+=lowbit(i))
  16. for(int j=y;j<=n;j+=lowbit(j))
  17. c[i][j]=(c[i][j]+val)%Mod;
  18. }
  19. int getsum(int x, int y) {
  20. int res = ;
  21.  
  22. for (int i = x; i; i -= lowbit(i)) {
  23. for (int j = y; j; j -= lowbit(j)) {
  24. res += c[i][j];
  25. }
  26. }
  27.  
  28. return res;
  29. }
  30. int main()
  31. {
  32. int m,i,a,b,x,y,z;
  33. char c[];
  34. scanf("%d%d",&n,&m);n++;
  35. for(i=;i<=m;i++){
  36. scanf("%s",c);
  37. if(c[]=='A'){
  38. scanf("%d%d%d",&x,&y,&z);
  39. add(x+,y+,z);
  40. }
  41. else {
  42. scanf("%d%d%d%d",&x,&y,&a,&b);
  43. printf("%d\n",((getsum(a+,b+)+getsum(x,y)-getsum(a+,y)-getsum(x,b+))%Mod+Mod)%Mod);
  44. }
  45. }
  46. return ;
  47. }

HihoCoder1336 Matrix Sum(二维树状数组求和)的更多相关文章

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

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

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

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

  3. HLJU 1188 Matrix (二维树状数组)

    Matrix Time Limit: 4 Sec  Memory Limit: 128 MB Description 给定一个1000*1000的二维矩阵,初始矩阵中每一个数都为1,然后为矩阵有4种操 ...

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

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

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

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

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

    题目大意:原题链接 题意很简单,就不赘诉了. 解题思路: 使用二维树状数组,很裸的题. 二维的写起来也很方便,两重循环. Add(int x,int y,int val)表示(x,y)-(n,n)矩形 ...

  7. POJ_2155 Matrix 【二维树状数组】

    一.题面 POJ2155 二.分析 楼教主出的题,是二维树状数组非常好的题,还结合了开关问题(开关变化的次数如果为偶数,状态不变,奇数状态相反). 题意就是给了一个二维的坐标平面,每个点初始值都是0, ...

  8. POJ2155 Matrix(二维树状数组||区间修改单点查询)

    Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row an ...

  9. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

随机推荐

  1. Unity中的全局坐标系和局部坐标系

      全局坐标系 描述游戏场景内所有物体位置和方向的基准,也称为世界坐标系.在Unity场景中创建的物体都是以全局坐标系中的坐标原点(0,0,0)来确定各自的位置的. 局部坐标系 每个物体都有其独立的坐 ...

  2. 如何上传整个项目或者是文件夹到github

    原文地址:https://www.cnblogs.com/cairsha/p/11430436.html   在做github个人主页的时候,使用github的readme写起来很麻烦,而且也不好加入 ...

  3. SQLite扫描

    SQLite的扫盲 SQLite的是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite的本身是Ç写的,而且体积很小,所以经常被集成到各种应用程序中,主要在手机的应用中使用. 之前没有遇到过关于 ...

  4. 【C/C++】什么是类型安全

    什么是类型安全 转自:http://hi.baidu.com/chenfalei/blog/item/f33ac0133500ac21dd540186.html 编程语言的最终梦想:静态类型安全 常听 ...

  5. Linux基础训练题型(下)

    8.在题3的基础上,使用命令调换passwd文件里root位置和/bin/bash位置?即将所有的第一列和最后一列位置调换? 例: 默认:root:x:0:0:root:/root:/bin/bash ...

  6. mac环境提示:make sure that /usr/local/bin is in your path

    今天我在Mac环境下安装了Homebrew和node.js后,输入node -v.brew.npm都提示: command not found,然后我查看了下Homebrew的安装日志,发现日志里有个 ...

  7. xshell设置

    登录脚本: #定义rz,sz自动下载路径 #保持窗口活动状态, 空闲时每120秒发送一个回车

  8. 开启httpfs

    参考: https://docs.cloudera.com/documentation/enterprise/6/6.2/topics/admin_httpfs.html#xd_583c10bfdbd ...

  9. 1. centos7 的安装

    选择上海时间 我们选择桌面版 选择手动配置分区 选择标准分区 修改主机名 开始安装 设置密码 设置用户名 接下来等待安装完 同样的操作再安装3台机器!!这里不多赘述. 安装完之后就重启 接下来给不同机 ...

  10. CentOS7下MySQL服务启动失败原因及解决方法

    在重启阿里的CentOS7服务器后,重启MySQL 出现错误 Starting mysqld (via systemctl): Job for mysqld.service failed becaus ...