1336 : Matrix Sum (hihocoder)
题目链接: 点击打开链接
二维树状数组,百度一大堆,我只是存代码的
#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)的更多相关文章
- Matrix Sum HihoCoder - 1336 二维树状数组 感觉好像二维差分。
#include<cstdio> #include<cstring> using namespace std; typedef long long ll; ; ; ll c[N ...
- 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 ...
- E - Evaluate Matrix Sum
Description Given a matrix, the elements of which are all integer number from 0 to 50, you are requi ...
- HihoCoder1336 Matrix Sum(二维树状数组求和)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given an N × N matrix. At the beginning every element ...
- Project Euler 345: Matrix Sum
题目 思路: 将问题转化成最小费用流 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #incl ...
- [HIHO]hihoCoder太阁最新面经算法竞赛7
题目链接:http://hihocoder.com/contest/hihointerview12 期末完事了,终于有时间成套刷题了.这套题比较简单,难度上感觉和上一套差不多.除了最后一个题是看了讨论 ...
- UVa 11149 Power of Matrix(倍增法、矩阵快速幂)
题目链接: 传送门 Power of Matrix Time Limit: 3000MS Description 给一个n阶方阵,求A1+A2+A3+......Ak. 思路 A1+A2+. ...
- POJ 3233 Matrix Power Series(矩阵高速功率+二分法)
职务地址:POJ 3233 题目大意:给定矩阵A,求A + A^2 + A^3 + - + A^k的结果(两个矩阵相加就是相应位置分别相加).输出的数据mod m. k<=10^9. 这 ...
- C++题解:Matrix Power Series ——矩阵套矩阵的矩阵加速
Matrix Power Series r时间限制: 1 Sec 内存限制: 512 MB 题目描述 给定矩阵A,求矩阵S=A^1+A^2+--+A^k,输出矩阵,S矩阵中每个元都要模m. 数据范围: ...
随机推荐
- Linux 主机被入侵后的处理案例
Linux主机被入侵后的处理案例 提交 我的留言 加载中 已留言 一次Linux被入侵后的分析 下面通过一个案例介绍下当一个服务器被rootkit入侵后的处理思路和处理过程,rootkit攻击是Lin ...
- python 图像识别转文字
rom PIL import Image import pytesseract #上面都是导包,只需要下面这一行就能实现图片文字识别 #text=pytesseract.image_to_string ...
- sklearn特征选择和分类模型
sklearn特征选择和分类模型 数据格式: 这里.原始特征的输入文件的格式使用libsvm的格式,即每行是label index1:value1 index2:value2这样的稀疏矩阵的格式. s ...
- 简化动态MERGE的SQL计算
MSSQL.ORACLE等数据库支持MERGE语句更新表.但表结构未知时,因为缺乏集合类数据.用存储过程获得表结构再动态拼出SQL很麻烦,代码会有几十行之多:相同原因,用Java等高级语言实现也不简单 ...
- C语言-二维背包问题
二维费用背包问题 问题: 二维费用的背包问题是指:对于每件物品,具有两种不同的费用:选择这件物品必须同时付出这两种代价:对于每种代价都有 一个可付出的最大值(背包容量).问怎样选择物品可以得到最大的价 ...
- Linq实现SQL in
比如 Id in (1,2,3) int[] a={1,2,3}; list.Where(x=>a.Contains(x.Id))
- Zoj2421 广搜
<span style="color:#330099;">/* M - 广搜 加强 Time Limit:2000MS Memory Limit:65536KB 64b ...
- 【每日Scrum】第五天(4.26) TD学生助手Sprint2站立会议
站立会议 组员 昨天 今天 困难 签到 刘铸辉 (组长) 今天增加了几个页面的子菜单,然后设计了几个要用的界面 今天和楠哥做了课程事件和日历表操作的例子,并尝试做时间表和日历表的数据库设计 安卓的数据 ...
- 【转】VMware 11.0 简体中文版|附永久密钥
VMware 11.0 简体中文版|附永久密钥 昨天,VMware虚拟机11.0 简体中文版正式发布,值得注意的是新版抛弃了32位系统支持,安装包体积大幅减小, 新增Windows 10 技术预览版支 ...
- vs2010音频文件压缩 调用lame_enc.dll将WAV格式转换成MP3
/* //My_lame.h */ #pragma once#include "stdafx.h"#include <windows.h>#include <st ...