题目链接

描述

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 ;
}

最新文章

  1. 零基础如何系统学习Java Web
  2. [css3]跑马灯
  3. phonegap 2.7 ios配置安装详细教程(2.9通用)
  4. oracle客户端精简绿色版-环境变量配置
  5. SQL创建链接服务器
  6. YII2 实现登录时候修改最新登录时间
  7. Ajax 实现无刷新分页
  8. UVA580-Critical Mass
  9. Apache错误:(20014)Internal error: Error retrieving pid file logs/httpd.pid
  10. maven项目导出依赖的Jar包以及项目本身以jar包形式导出详细教程
  11. houseAPP
  12. android银行卡匹配、详情展开动画、仿爱奇艺视频拖拽、扫码识别手机号等源码
  13. Docker Kubernetes Volume 本地数据卷
  14. php loop循环 拿到键名
  15. codeforces966 A
  16. JavaScript进阶系列03,通过硬编码、工厂模式、构造函数创建JavaScript对象
  17. vue - 父组件数据变化控制子组件类名切换
  18. 蜗牛慢慢爬 LeetCode 11. Container With Most Water [Difficulty: Medium]
  19. angular路由传参和获取路由参数的方法
  20. 去掉第一次ssh连接的yes问题

热门文章

  1. WebView简单用法
  2. oracle导入导出操作
  3. ZOJ 3019 Puzzle
  4. POJ 2524 Ubiquitous Religions 【并查集】
  5. 第一次接触Arduino
  6. Pyhton学习——Day61
  7. bootstrap fileinput控件 + django后台上传、回显简单使用
  8. Flask-Babel 使用简介(翻译文档)
  9. linux 模块编译步骤(原)
  10. python_函数传递列表