HDU 6336 Matrix from Arrays (杭电多校4E)
遇事不决先打表。
然后会发现(个屁)大的矩形是由一个2L*2L的矩形重复出现组成的然后我们就可以这个矩形分成四个点到(0, 0)点的矩形,这样问题就变成了求四个到顶点(0, 0)的矩形的面积,然后就先去求这里面完整的块数,然后去找边缘的有一边是完整的块,然后找最右下角的没有完整的块的面积,然后加起来就可了
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+;
const int maxm = ;
const int mod = 1e9+;
using namespace std; int n, m, tol, T;
int L;
int A[];
int M[][];
ll sx[];
ll sy[];
ll sum; void init() {
sum = ;
memset(A, , sizeof A);
memset(M, , sizeof M);
memset(sx, , sizeof sx);
memset(sy, , sizeof sy);
} ll solve(int x, int y) {
ll ans = ;
int cx = x/L;
int cy = y/L;
ll t = 1ll * cx * cy;
ans += 1ll * t * sum;
int x1 = x % L;
int y1 = y % L;
ll s = ;
for(int i=; i<=x1; i++) s += sx[i];
ans += s * cy;
s = ;
for(int i=; i<=y1; i++) s += sy[i];
ans += s * cx;
for(int i=; i<=x1; i++) {
for(int j=; j<=y1; j++) {
ans += M[i][j];
}
}
return ans;
} int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d", &T);
while(T--) {
init();
scanf("%d", &L);
for(int i=; i<L; i++) scanf("%d", &A[i]);
int cursor = ;
for(int i=; i<=*L; i++) {
for(int j=; j<=i; j++) {
M[j][i - j + ] = A[cursor];
cursor = (cursor + ) % L;
}
}
L <<= ;
for(int i=; i<=L; i++) {
for(int j=; j<=L; j++) {
sy[j] += M[i][j];
sx[i] += M[i][j];
}
sum += sx[i];
}
/*
for(int i=1; i<=L; i++) for(int j=1; j<=L; j++) printf("%d%c",M[i][j], j==L ? '\n' : ' \t');
for(int i=1; i<=L; i++) printf("sx%d = %d\n", i, sx[i]);
for(int i=1; i<=L; i++) printf("sy%d = %d\n", i, sy[i]);
*/
int q;
scanf("%d", &q);
while(q--) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1++, y1++, x2++, y2++;
ll ans = solve(x2, y2);
ans -= solve(x1-, y2);
ans -= solve(x2, y1-);
ans += solve(x1-, y1-);
printf("%lld\n", ans);
}
}
return ;
}
HDU 6336 Matrix from Arrays (杭电多校4E)的更多相关文章
- HDU 6336 Matrix from Arrays
Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- hdu 5328 Problem Killer(杭电多校赛第四场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328 题目大意:找到连续的最长的等差数列or等比数列. 解题思路:1.等差等比的性质有很多.其中比较重 ...
- HDU 5734 Acperience (公式推导) 2016杭电多校联合第二场
题目:传送门. #include <iostream> #include <algorithm> #include <cstdio> #include <cs ...
- HDU 4627 The Unsolvable Problem 杭电多校联赛第三场1009 数学题
题意描述:给出一个n,要求在所有满足n = a+b的a和b里面求a和b的最小公倍数最大的两个数的最小公倍数. 解题报告:比赛的时候看到这个题的第一反应就是寻找这两个数一定是在a和b比较接近的地方找,这 ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
- 杭电多校第四场 E Matrix from Arrays
Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 ...
- 2018 Multi-University Training Contest 1 杭电多校第一场
抱着可能杭电的多校1比牛客的多校1更恐怖的想法 看到三道签到题 幸福的都快哭出来了好吗 1001 Maximum Multiple(hdoj 6298) 链接:http://acm.hdu.edu. ...
- HDU 4920(杭电多校训练#5 1010 题) Matrix multiplication(不知道该挂个什么帽子。。。)
题目地址:pid=4920">HDU 4920 对这个题简直无语到极点. . .竟然O(n^3)的复杂度能过....方法有三.. 1:进行输入优化和输出优化. . (前提是你的输入优化 ...
随机推荐
- 【问题解决方案】之 Word 公式编辑器 使用小tips
输入空格:shift+Ctrl+space 换行:直接回车.之后在上方菜单栏中选择"在等号处对齐"
- NGINX Docs | Load Balancing Apache Tomcat Servers with NGINX Open Source and NGINX Plus
NGINX Docs | Load Balancing Apache Tomcat Servers with NGINX Open Source and NGINX Plushttps://docs. ...
- C# 父子页面传值
业务需求是:父页面点击“选择任务”按钮进入任务列表页.(项目进度周报) 父页面如下: 任务列表页: 选择某一个任务,点击“确定”后返回父页面所需数据. 父页面“选择任务” 按钮触发事件. /// &l ...
- [FreeBuff]Trojan.Miner.gbq挖矿病毒分析报告
Trojan.Miner.gbq挖矿病毒分析报告 https://www.freebuf.com/articles/network/196594.html 竟然还有端口转发... 这哥们.. 江民安全 ...
- java学习之—链表(3)
/** * 使用链表实现队列 * Create by Administrator * 2018/6/19 0019 * 下午 4:37 **/ public class Link { public l ...
- 使用mysqlbinlog恢复数据
前提:mysql数据库开启了binlog日志,并且有对应的日志文件 起因:今天由于同事对数据库的误操作不小心删除了一条数据 方法一:通过binlog日志文件恢复数据 通过mysqlbinlog恢复My ...
- JQ 动态修改/替换某个节点的内容
<div class="box">我们定位于中国心理行业第一<div> $(".box").html($(".box&quo ...
- Python——线程1
多线程并发 from threading import Thread import time #多线程并发 def func(n): time.sleep(1) print(n) for i in r ...
- EChart.js 笔记二
交互组件 Echart.js 中交互组件比较多.例如: legend(图例).title(标题组件).visualMap(视觉映射组件).dataZoom(数据缩放组件).timeline(时间线组件 ...
- 两种从spring容器获取bean方式