题目链接: 点击打开链接

二维树状数组,百度一大堆,我只是存代码的

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string> using namespace std;
typedef long long int LL;
const int INF=2e9+1e8;
const int MM=1010;
const LL MOD=1e9+7; LL n,m,bitnum[MM][MM]; LL lowbit(LL x)
{
return x&(-x);
}
void add(LL xx,LL yy,LL num)
{
for(int x=xx;x<=n+1;x+=lowbit(x))
{
for(int y=yy;y<=n+1;y+=lowbit(y))
{
bitnum[x][y]+=num;
}
}
}
LL sum(LL l,LL r)
{
LL ans=0;
for(int x=l;x>0;x-=lowbit(x))
{
for(int y=r;y>0;y-=lowbit(y))
{
ans+=(bitnum[x][y])%MOD;
}
}
return ans%MOD;
}
LL getsum(LL x1,LL y1,LL x2,LL y2)
{
LL ans=sum(x2,y2)-sum(x1-1,y2)-sum(x2,y1-1)+sum(x1-1,y1-1);
while(ans<0) ans+=MOD;
return ans;
} int main()
{
memset(bitnum,0,sizeof(bitnum));
cin>>n>>m;
for(int i=0;i<m;i++)
{
char opt[10];
LL x1,y1,x2,y2,val;
cin>>opt;
if(opt[0]=='A')
{
cin>>x1>>y1>>val;
add(x1+1,y1+1,val);
}
else
{
cin>>x1>>y1>>x2>>y2;
cout<<getsum(x1+1,y1+1,x2+1,y2+1)<<endl;
}
}
return 0;
}

1336 : Matrix Sum (hihocoder)的更多相关文章

  1. Matrix Sum HihoCoder - 1336 二维树状数组 感觉好像二维差分。

    #include<cstdio> #include<cstring> using namespace std; typedef long long ll; ; ; ll c[N ...

  2. hihocode 1336 Matrix Sum 【二维树状数组】

    题目 两个操作: 1. Add x y value: Add value to the element Axy. (Subscripts starts from 0 2. Sum x1 y1 x2 y ...

  3. E - Evaluate Matrix Sum

    Description Given a matrix, the elements of which are all integer number from 0 to 50, you are requi ...

  4. HihoCoder1336 Matrix Sum(二维树状数组求和)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given an N × N matrix. At the beginning every element ...

  5. Project Euler 345: Matrix Sum

    题目 思路: 将问题转化成最小费用流 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #incl ...

  6. [HIHO]hihoCoder太阁最新面经算法竞赛7

    题目链接:http://hihocoder.com/contest/hihointerview12 期末完事了,终于有时间成套刷题了.这套题比较简单,难度上感觉和上一套差不多.除了最后一个题是看了讨论 ...

  7. UVa 11149 Power of Matrix(倍增法、矩阵快速幂)

    题目链接: 传送门 Power of Matrix Time Limit: 3000MS      Description 给一个n阶方阵,求A1+A2+A3+......Ak. 思路 A1+A2+. ...

  8. POJ 3233 Matrix Power Series(矩阵高速功率+二分法)

    职务地址:POJ 3233 题目大意:给定矩阵A,求A + A^2 + A^3 + - + A^k的结果(两个矩阵相加就是相应位置分别相加).输出的数据mod m. k<=10^9.     这 ...

  9. C++题解:Matrix Power Series ——矩阵套矩阵的矩阵加速

    Matrix Power Series r时间限制: 1 Sec 内存限制: 512 MB 题目描述 给定矩阵A,求矩阵S=A^1+A^2+--+A^k,输出矩阵,S矩阵中每个元都要模m. 数据范围: ...

随机推荐

  1. indy9在程序关闭时出现terminate thread timeout的BUG解决办法

    indy9在程序关闭时出现terminate thread timeout的BUG解决办法 INDY9线程有BUG,在退出程序的时候会报错:terminate thread timeout(终止线程超 ...

  2. Android-->状态栏高度,导航栏高度,Window高度,DecorView高度,heightPixels

    1:DecorView的高度 DecorView的高度代表的是: 整个装饰窗口的高度, 这个高度包括:状态烂的高度和导航栏的高度.(状态栏和导航栏通常叫做装饰窗口, 而ActionBar不属于装饰窗口 ...

  3. ubuntu配置django

    安装 安装Apache sudo apt-get install apache2 安装Django 下载Django 安装mod_wsgi sudo apt-get install libapache ...

  4. C#中通过反射获取类中非公有成员

    public class NGlbGlobeXComm { public static T GetPrivateField<T>(object instance, string field ...

  5. dom4j的xpath查找xml的指定节点

    递归遍历所有节点http://blog.csdn.net/sidihuo/article/details/47318723 获取Document SAXReader saxReader = new S ...

  6. POJ2386 Lake Counting 【DFS】

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20782   Accepted: 10473 D ...

  7. JavaScript 日期格式化 简单有用

    JavaScript 日期格式化 简单有用 代码例如以下,引入jquery后直接后增加下面代码刷新可測试 Date.prototype.Format = function (fmt) { //auth ...

  8. 如何重建一个损坏的调用堆栈(callstack)

    原文作者:Aaron Ballman原文时间:2011年07月04日原文地址:http://blog.aaronballman.com/2011/07/reconstructing-a-corrupt ...

  9. Num 34 : HDOJ : 1205 吃糖果 [ 狄利克雷抽屉原理 ]

           抽屉原理:          桌上有十个苹果,要把这十个苹果放到九个抽屉里,不管如何放,我们会发现至少会有一个抽屉里面至少放两个苹果.          这一现象就是我们所说的" ...

  10. 【Android Studio探索之路系列】之十:Gradle项目构建系统(四):Android Studio项目多渠道打包

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells github:https://github.co ...