BZOJ_2901_矩阵求和_前缀和
BZOJ_2901_矩阵求和_前缀和
Description
Input
Output
Sample Input
1 9 8
3 2 0
1 8 3
9 8 4
0 5 15
1 9 6
1 1 3 3
2 3 1 2
Sample Output
388
【数据规模和约定】
对30%的数据满足,n <= 100。
对100%的数据满足,n <= 2000,m <= 50000,输入数据中矩阵元素 < 100,a,b,c,d <= n。
$=\sum\limits_{k=1}^{n}\sum\limits_{i=1}^{n}A_{ik}\sum\limits_{j=1}^{y}B_{kj}$
// bzoj-judger-enable-ogay
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int sa[2050][2050],sb[2050][2050],n,m;
char buf[100000],*p1=buf,*p2=buf;
#define nc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
__attribute__((optimize("-O998244353")))int rd() {
int x=0; char s=nc();
while(s<'0'||s>'9') s=nc();
while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+s-'0',s=nc();
return x;
}
char pbuf[100000],*pp=pbuf;
__attribute__((optimize("-O998244353")))void push(const char ch) {
if(pp-pbuf==100000) fwrite(pbuf,1,100000,stdout),pp=pbuf;
*pp++=ch;
}
__attribute__((optimize("-O998244353")))void write(ll x) {
static int sta[70];
int top=0;
do{sta[++top]=x%10,x/=10;}while(x);
while(top) push(sta[top--]+'0');
push('\n');
}
__attribute__((optimize("-O998244353")))ll qu(int x,int y,int z,int w) {
int i;
ll re=0;
for(i=1;i<=n;i++) re+=ll(sa[z][i]-sa[x-1][i])*(sb[i][w]-sb[i][y-1]);
return re;
}
__attribute__((optimize("-O998244353")))int main() {
n=rd(); m=rd();
register int i,j,x;
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
x=rd(); sa[i][j]=sa[i-1][j]+x;
}
}
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
x=rd(); sb[i][j]=sb[i][j-1]+x;
}
}
int y,z,w;
while(m--) {
x=rd(); y=rd(); z=rd(); w=rd();
if(x>z) swap(x,z); if(y>w) swap(y,w);
write(qu(x,y,z,w));
}
fwrite(pbuf,1,pp-pbuf,stdout);
}
BZOJ_2901_矩阵求和_前缀和的更多相关文章
- BZOJ 2901: 矩阵求和
2901: 矩阵求和 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 411 Solved: 216[Submit][Status][Discuss] ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- poj 1195:Mobile phones(二维线段树,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14391 Accepted: 6685 De ...
- BZOJ_2738_矩阵乘法_整体二分
BZOJ_2738_矩阵乘法_整体二分 Description 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. Input 第一行两个数N,Q,表示矩阵大小和询问组数: 接下 ...
- 【BZOJ5293】[BJOI2018]求和(前缀和,LCA)
[BZOJ5293][BJOI2018]求和(前缀和,LCA) 题面 BZOJ 洛谷 题解 送分题??? 预处理一下\(k\)次方的前缀和. 然后求个\(LCA\)就做完了?... #include& ...
- UVA 11149-Power of Matrix(等比矩阵求和)
给定一个矩阵A 要求A + A^2 + A^3 +…. A^k: 对于到n的等比矩阵求和 如果n是偶数: 如果n是奇数: #include<stdio.h> #include<s ...
- YTU 2442: C++习题 矩阵求和--重载运算符
2442: C++习题 矩阵求和--重载运算符 时间限制: 1 Sec 内存限制: 128 MB 提交: 1457 解决: 565 题目描述 有两个矩阵a和b,均为2行3列.求两个矩阵之和.重载运 ...
- YTU 2640: 编程题:运算符重载---矩阵求和
2640: 编程题:运算符重载---矩阵求和 时间限制: 1 Sec 内存限制: 128 MB 提交: 484 解决: 190 题目描述 /* 有两个矩阵a和b,均为2行3列.求两个矩阵之和. 重 ...
- HDU 6336.Problem E. Matrix from Arrays-子矩阵求和+规律+二维前缀和 (2018 Multi-University Training Contest 4 1005)
6336.Problem E. Matrix from Arrays 不想解释了,直接官方题解: 队友写了博客,我是水的他的代码 ------>HDU 6336 子矩阵求和 至于为什么是4倍的, ...
随机推荐
- hive界面工具SQL Developer的安装;使用sql developer连接hive;使用sql developer连接mysql
需要oracle帐号登录后下载 1.下载: http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/inde ...
- The bean 'xxx' could not be injected as a 'xxx'because it is a JDK dynamic proxy that implements
启动springboot项目的时候示以下错误 Error starting ApplicationContext. To display the conditions report re-run yo ...
- 怎样让Eclipse的智能提示像VS一样霸气
说起来用Eclipse也有一段时间了.相信每个用过的人都知道他的智能提示功能真的是糟糕透了,与VisualStudio2008简直不是一个档次的!我就纳闷了,他为什么不弄好一点呢.今天我实在是忍不住了 ...
- odoo 有哪些文档资源
// openbook [覆盖 openerp 7 及之前版本] https://doc.odoo.com/ // 最新的 odoo documentation user[覆盖 odoo 9] ...
- linux基础(5)- nginx服务、nfs服务
一.nginx服务 源码安装: yum install gcc-* glibc-* openssl openssl-devel pcre pcre-devel zlib zlib-devel -yls ...
- Android Volley分析(一)——结构
Volley是Android系统下的一个网络通信库.为Android提供简单高速的网络操作(Volley:Esay, Fast Networking for Android),以下是它的结构: 既然是 ...
- 【每日Scrum】第六天(4.16) TD学生助手Sprint1阶段性成果
TD学生助手Sprint1阶段性成果(4.16) 任务看板 站立会议内容 组员 昨天 今天 困难 签到 刘铸辉 (组长) 和叶姐,静姐修改页面布局和图片显示,保证界面的亲切. 和大家一起做演示PPT, ...
- UUID随机字符串
public static void main(String[] args){ System.out.println(UUID.randomUUID().toString()); } //输出:698 ...
- 斯坦福公开课:Developing IOS 8 App with Swift(1-3)心得体会
最近开始学习Swift开发移动程序.跟随斯坦福大学的公开课进行自学. 这真是一个美好的时代,虽然不能在斯坦福求学,但是可以观看录制的授课录像.讲义,好似老师在给我们上课一样! 心得: 1.每节课信息量 ...
- HttpUtility.UrlEncode,Request.RawUrl,HttpUtility.UrlDecode,HttpUtility.UrlPathEncode,Uri.EscapeDataString
碰到同样问题, 记录一下. 引自:https://www.cnblogs.com/ken-admin/p/5826480.html HttpUtility.UrlDecode(url),从Encode ...