Problem E. Matrix from Arrays

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 501    Accepted Submission(s): 210

Problem Description
Kazari has an array $A$ length of $L$, she plans to generate an infinite matrix $M$ using $A$.
The procedure is given below in C/C++:

int cursor = 0;

for (int i = 0; ; ++i) {
for (int j = 0; j <= i; ++j) {
M[j][i - j] = A[cursor];
cursor = (cursor + 1) % L;
}
}

Her friends don't believe that she has the ability to generate such a huge matrix, so they come up with a lot of queries about $M$, each of which focus the sum over some sub matrix. Kazari hates to spend time on these boring queries. She asks you, an excellent coder, to help her solve these queries.

 
Input
The first line of the input contains an integer $T$ $(1 \le T \le 100)$ denoting the number of test cases.
Each test case starts with an integer $L$ $(1 \le L \le 10)$ denoting the length of $A$.
The second line contains $L$ integers $A_0, A_1, ..., A_{L - 1}$ $(1 \le A_i \le 100)$.
The third line contains an integer $Q$ $(1 \le Q \le 100)$ denoting the number of queries.
Each of next $Q$ lines consists of four integers $x_0, y_0, x_1, y_1$ $(0 \le x_0 \le x_1 \le 10 ^ 8, 0 \le y_0 \le y_1 \le 10 ^ 8)$ querying the sum over the sub matrix whose upper-leftmost cell is $(x_0, y_0)$ and lower-rightest cell is $(x_1, y_1)$.
 
Output
For each test case, print an integer representing the sum over the specific sub matrix for each query.
 
Sample Input
1
3
1 10 100
5
3 3 3 3
2 3 3 3
2 3 5 8
5 1 10 10
9 99 999 1000
 
Sample Output
1
101
1068
2238
33076541
 
Source
 
Recommend
chendu
 
分析:就是个矩阵前缀和处理,水题~
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define LL long long
#define elif else if
#define range(i,a,b) for(auto i=a;i<=b;++i)
#define rerange(i,a,b) for(auto i=a;i>=b;--i)
#define itrange(i,a,b) for(auto i=a;i!=b;++i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
LL A[],M[][],L,t;
void init(){
cin>>L;
range(i,,L-)scanf("%lld",A+i);
LL cursor = ;
range(i,,L*-)
range(j,,i){
if(j<(L<<) and i-j<(L<<))M[j][i - j] = A[cursor];
cursor = (cursor + ) % L;
}
L<<=;
}
LL work(int n,int m){
if(n< or m<)return ;
return M[L-][L-]*(n/L)*(m/L)+M[n%L][L-]*(m/L)+M[L-][m%L]*(n/L)+M[n%L][m%L];
}
void solve(){
range(i,,L-)
range(j,,L-){
if(i)M[i][j]+=M[i-][j];
if(j)M[i][j]+=M[i][j-];
if(i and j)M[i][j]-=M[i-][j-];
}
int Q,x1,x2,y1,y2;
scanf("%d",&Q);
while(Q--){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("%lld\n",work(x2,y2)-work(x1-,y2)-work(x2,y1-)+work(x1-,y1-));
}
}
int main() {
cin>>t;
while(t--) {
init();
solve();
}
return ;
}

HDU 6336 Matrix from Arrays的更多相关文章

  1. HDU 6336 Matrix from Arrays (杭电多校4E)

    遇事不决先打表. 然后会发现(个屁)大的矩形是由一个2L*2L的矩形重复出现组成的然后我们就可以这个矩形分成四个点到(0, 0)点的矩形,这样问题就变成了求四个到顶点(0, 0)的矩形的面积,然后就先 ...

  2. HDU 6336.Problem E. Matrix from Arrays-子矩阵求和+规律+二维前缀和 (2018 Multi-University Training Contest 4 1005)

    6336.Problem E. Matrix from Arrays 不想解释了,直接官方题解: 队友写了博客,我是水的他的代码 ------>HDU 6336 子矩阵求和 至于为什么是4倍的, ...

  3. hdu多校第4场E. Matrix from Arrays HDU 二维前缀和

    Problem E. Matrix from Arrays Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total S ...

  4. 2018 Multi-University Training Contest 4 Problem E. Matrix from Arrays 【打表+二维前缀和】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6336 Problem E. Matrix from Arrays Time Limit: 4000/20 ...

  5. 杭电多校第四场 E Matrix from Arrays

    Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 ...

  6. HDU 6336 子矩阵求和

    Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 ...

  7. HDU 4920 Matrix multiplication(bitset)

    HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...

  8. HDU 2686 Matrix 3376 Matrix Again(费用流)

    HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...

  9. 杭电第四场 hdu6336 Problem E. Matrix from Arrays 打表找规律 矩阵前缀和(模板)

    Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 ...

随机推荐

  1. [BZOJ2440]完全平方数解题报告|莫比乌斯函数的应用

    完全平方数 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平方数.他觉得这些数看起来很令人难受.由此,他也讨厌所有是完全平方数的正整数倍的数.然而这丝毫不影响他对其他数的热爱.  这天是小X的生日 ...

  2. RabbitMq related

    # RabbitMq related Integration of message queuing tools with systems is the usual solution to handle ...

  3. 2018 Multi-University Training Contest 1-1002 -Balanced Sequence(括号匹配+贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6299 题目: 题意:t组数据,每组数据给你一个n表示给你n个括号串,这n个括号串之间进行组合,求能够匹 ...

  4. I题 hdu 1234 开门人和关门人

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1234 开门人和关门人 Time Limit: 2000/1000 MS (Java/Others)   ...

  5. DIV+CSS左右列高度自适应问题

    其实解决DIV+CSS左右两列高度自适应的方法就是要注意两点:一是在最外层加上overflow:hidden,然后在左边列加上margin-bottom:-9999px;padding-bottom: ...

  6. eComStation 1.2

    https://thomas0008.ctfile.com/u/75519/87485 https://thomas0008.ctfile.com/downhtml/75519/428846/1508 ...

  7. python中的map、reduce、filter、sorted函数

    map.reduce.filter.sorted函数,这些函数都支持函数作为参数. map函数 map() 函数语法:map(function, iterable, ...) function -- ...

  8. 8:django sessions(会话)

    django会话 django提供对匿名会话全方位的支持,会话框架可以存储和检索每个站点访问者的任意数据.会话数据是存储在服务器端的,并且简要了发送和接受cookie的过程,cookies只包含一个s ...

  9. python_day3学习笔记

    set集合 python的set是一个无序不重复元素集,基本功能包括关系测试和消除重复元素. 集合对象还支持并.交.差.对称差等. sets 支持 x in set. len(set).和 for x ...

  10. 如何测试一台主机的IP和端口是否能连通,ping telnet

    通过ping 判断一台主机是否开机. 通过:telnet 121.199.167.99 61616  判断一台主机的端口是否能连通. 本机------本地防火墙-------本地路由器-------- ...