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:进行输入优化和输出优化. . (前提是你的输入优化 ...
随机推荐
- MongoDB——待整理
MongoDB mongoose——http://mongoosejs.com/ npm i mongoose Mongoose 通过外键与另一张表建立关联:Mongoose Populate 基本使 ...
- pl/sql实现打印九九乘法表
学习PL/SQL循环的时候写的,记录一下. declare v_number1 ); -- 外层循环变量 v_number2 ); -- 内层循环变量 begin .. -- 开始外层循环 loop ...
- [转帖]Htop 使用详解
htop使用详解 https://www.cnblogs.com/yqsun/p/5396363.html 一.Htop的使用简介 大家可能对top监控软件比较熟悉,今天我为大家介绍另外一个监控软件H ...
- Day 5-5 绑定方法与非绑定方法
绑定方法与非绑定方法: 在类内部定义的绑定方法,分两大类: classmehtod是给类用的,即绑定到类,类在使用时会将类本身当做参数传给类方法的第一个参数(即便是对象来调用也会将类当作第一个参数传入 ...
- :before添加图片,IE8兼容
这是项目开发中遇到的奇怪的小问题: 在IE8下出现按钮点击后消失了,鼠标点击页面后却又出现: 最初的代码:添加背景图片的方法,这样是存在兼容问题的. 更改后代码:content中添加图片,完美兼容IE ...
- js获取数组中相同元素数量
<script> var array = new Array(1,2,5,1,4,4,2,3,5,1,1,5,5,5,6,7,3,9,9,10); var arr = new Array( ...
- PreparedStatement和Statement
1 . PreparedStatement 接口继承 Statement , PreparedStatement 实例包含已编译的 SQL 语句,所以其执行速度要快于 Statement 对象. 2 ...
- 在eclipse中spring的xml配置文件标签中class路径全限定名自动提示设置
这个自动提示其实很简单,没有网上说的那些要在help下的Install中输入网址来下载更新一堆东西那么复杂. 只需要打开Help — — >Eclipse Marketplace... 然后在该 ...
- Java使用RabbitMQ之消息确认(confirm模板)
RabbitMQ生产者消息确认Confirm模式,分为普通模式.批量模式和异步模式,本次举例为普通模式. 源码: package org.study.confirm4; import com.rabb ...
- How to recovery compiz
sudo apt install compizconfig-settings-manager dconf reset -f /org/compiz/ setsid unity dconf list / ...