题目链接

描述

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 y1: Return the sum of every element Axy for x1xx2, y1yy2.

输入

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 ≤ x1x2 < N, 0 ≤ y1y2 < N

输出

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

----------------------------------------------------------------------------------------------------------------------

破题,non-negative number denoting the sum modulo ,wa了好几次

#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long LL; using namespace std;
const int N = ;
const LL MOD = 1e9+; int n,m;
LL sum[N][N];
int lowbit(int data){
return data&(-data);
} void add(int x,int y,int d){
for(int i=x;i<=n;i+=lowbit(i))
for(int j=y;j<=n;j+=lowbit(j)){
sum[i][j] += d;
sum[i][j] %= MOD;
}
}
LL query(int x,int y){
LL ret = ;
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j)){
ret += sum[i][j];
ret %= MOD;
}
return ret;
}
int main(){
cin>>n>>m; char str[];
memset(sum,,sizeof(sum));
int x1,y1,x2,y2,d;
while(m--){
scanf("%s",str);
if(str[]=='A'){
scanf("%d%d%d",&x1,&y1,&d);
add(x1+,y1+,d);
}
else{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
LL total = query(x2+,y2+);
LL small = query(x1+,y1+);
LL s1 = query(x2+,y1+);
LL s2 = query(x1+,y2+);
printf("%lld\n",((total+small-s1-s2)%MOD+MOD)%MOD);
}
}
return ;
}

hiho 172周 - 二维树状数组模板题的更多相关文章

  1. poj1195二维树状数组模板

    二维树状数组和一维的也差不多,改一下add和query函数即可:即按行修改,行内单点修改即可 /* 二维树状数组,询问一个二维区间内的数之和 */ #include<iostream> # ...

  2. POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】

    <题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...

  3. POJ 1195 Mobile phones【二维树状数组】

    <题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...

  4. 模板:二维树状数组 【洛谷P4054】 [JSOI2009]计数问题

    P4054 [JSOI2009]计数问题 题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入输出格式 ...

  5. POJ1195(二维树状数组)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 17176   Accepted: 7920 De ...

  6. 【bzoj1452】[JSOI2009]Count 二维树状数组

    题目描述 输入 输出 样例输入 样例输出 1 2 题解 二维树状数组 一开始没看到 1≤c≤100 ,想到了主X树和X块,结果发现c的范围那么小... 二维树状数组水题,和一维的一样,向上修改,向下查 ...

  7. 二维树状数组总结&&【洛谷P4514】 上帝造题的七分钟

    P4514 上帝造题的七分钟 题目描述 "第一分钟,X说,要有矩阵,于是便有了一个里面写满了00的n×mn×m矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为(a,b)(a,b),右下 ...

  8. 二维树状数组 BZOJ 1452 [JSOI2009]Count

    题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...

  9. HDU1559 最大子矩阵 (二维树状数组)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)  ...

随机推荐

  1. Typescript 模拟实现 多继承

    class Animal{ eat():void{ alert("animal eat"); } } class Mamal extends Animal{ breathe() : ...

  2. Python学习——BeautifulSoup篇

    BeautifulSoup     Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beau ...

  3. SQL Server 2014 中,新建登录用户,分配权限,并指定该用户的数据

    一.运行环境 系统:Windows 10数据库:SQL Server 2014数据库名: APP     新建的用户名: app 二.操作步骤 1.打开 MS SQL Server Managemen ...

  4. Hello World Spring MVC

    1, Setup Development Environment 1.1, Java SDK | ~ @ yvan-mac (yvan) | => java -version java vers ...

  5. Imperative programming

    In computer science, imperative programming is a programming paradigm that uses statements that chan ...

  6. 激情世界杯,盛夏大放价,CDR 618返场继续嗨

    最近被刷屏应该就是世界杯.世界杯和世界杯了... 进行了到第七天的球迷们,你们还好么 私房钱还剩下多少?上班有没有请假迟到? 哎,中国的小龙虾都去俄罗斯了,就国足队员没去… 满屏而来的不仅是手机朋友圈 ...

  7. Java校验8位字符串是否为正确的日期格式

    import java.text.ParseException; import java.text.SimpleDateFormat; /** * 校验8位字符串是否为正确的日期格式 * @autho ...

  8. javascript编程风格(粗略笔记)

    1.空格 紧凑型: project.MyClass = function(arg1, arg2){ 松散型: for( i = 0; i < length; i++ ){ 2.代码行长度 最多8 ...

  9. 2.安装Cython

    许多科学的Python发行版,例如Anaconda,Enthought Canopy和Sage,捆绑Cython并且不需要设置. 与大多数Python软件不同,Cython需要在系统上存在C编译器.获 ...

  10. SpringBoot2.0 监听器ApplicationListener的使用-监听ApplicationReadyEvent事件

    参考:http://www.shareniu.com/article/73.htm 一.需求是想将我的写一个方法能在项目启动后就运行,之前使用了redis的消息监听器,感觉可以照着监听器这个思路做,于 ...