【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

找个规律会发现
M[i][j] = M[i-2*L][j] = M[i][j-2*L]
先预处理出来(1,1)-(2L,2L)这个矩阵以及他的二维前缀和

那么对于要求的(x0,y0)-(x1,y1)这个矩阵。

可以用若干个(1,1)-(x,y)这样的前缀矩阵通过加加减减算出来。

对于(1,1)-(x,y)这样的矩阵。

显然是由若干个(1,1)-(2L,2L)矩阵合并而成的(x/L)*(y/L)个。

多余的部分(下边,右下角以及右边)也能很快的求得。(利用(1,1)-(2L,2L)这个矩阵的前缀和

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define res(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std; const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int MAXL = 10; int L,A[MAXL+10],M[MAXL*2+10][MAXL*2+10]; void creat_M(){
int cursor = 0,cnt = 0;
for (int i = 0;;++i){
for (int j = 0;j <= i;j++){
int x = j+1,y = i-j+1;
if (x>=1 && x<= 2*L && y>=1 && y<=2*L) {
M[x][y] = A[cursor];
cnt++;
if (cnt==4*L*L){
return;
}
}
cursor = (cursor + 1)%L;
}
}
} LL calc(int x,int y){
LL temp1 = 1LL*M[L][L]*(x/L)*(y/L);
LL temp2 = 1LL*M[x%L][L]*(y/L);
LL temp3 = 1LL*M[L][y%L]*(x/L);
LL temp4 = M[x%L][y%L];
return temp1+temp2+temp3+temp4;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
while (T--){
cin >> L;
rep1(i,0,L-1) cin >> A[i];
memset(M,0,sizeof M);
creat_M();
rep1(i,1,2*L)
rep1(j,1,2*L)
M[i][j] = M[i][j] + M[i-1][j] + M[i][j-1] -M[i-1][j-1];
L*=2;
int Q;
cin >> Q;
while (Q--){
int xx0,yy0,xx1,yy1;
cin >> xx0 >> yy0 >> xx1 >> yy1;
xx0++;yy0++;xx1++;yy1++;
LL ans = calc(xx1,yy1)-calc(xx0-1,yy1)-calc(xx1,yy0-1)+calc(xx0-1,yy0-1);
cout<<ans<<endl;
}
}
return 0;
}

【hdu 6336】 Matrix from Arrays的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【HDU 5015】233 Matrix

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5015 [算法] 矩阵乘法 [代码] #include<bits/stdc++.h> u ...

  8. 【NOIP模拟】matrix(简化矩阵)

    题目背景 SOURCE:NOIP2016-RZZ-1 题目描述 给出两个 N×N 的矩阵 A.B,矩阵每行每列标号 0-N-1 .定义这两个矩阵的乘积 AB 为

  9. 【POJ 3233】Matrix Power Series

    [题目链接] 点击打开链接 [算法] 要求 A^1 + A^2 + A^3 + ... + A^k 考虑通过二分来计算这个式子 : 令f(k) = A^1 + A^2 + A ^ 3 + ... + ...

随机推荐

  1. Swift学习——类的定义,使用,继承,构造等(五)

    Swift学习--类的定义,使用.继承,构造等(五) 类的使用说明 1 使用class和类名来创建一个类名,比如: class student 2 类中属性的声明和常量和变量一样,唯一的差别就是他们的 ...

  2. Notepad++如何编译、运行Java

    首先要让Notepad++编译和运行Java,前提是电脑里已经配置好了Java的环境(这里可以参考我博客里关于Java环境配置的那篇随笔). 在Notepad++上面的选项栏中找到 插件---> ...

  3. udev的使用-minicom没有权限打开串口,更改 ttyUSB0 的权限

    udev的使用-minicom没有权限打开串口,更改 ttyUSB0 的权限 使用minicom打开串口会提示没有权限,必需要用 sudo,怎样更改串口设备的权限能够让普通用户读写呢? 事实上仅仅要更 ...

  4. C#实体转换

    using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using S ...

  5. 2016.04.18,英语,《Vocabulary Builder》Unit 15

    term/termin, comes from the Latin verb terminare, 'to limit, bound, or set limits to', or the relate ...

  6. nyoj--170--网络的可靠性(水题)

    网络的可靠性 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 A公司是全球依靠的互联网解决方案提供商,也是2010年世博会的高级赞助商.它将提供先进的网络协作技术,展示其 ...

  7. poj--3624--Charm Bracelet(动态规划 水题)

    Home Problem Status Contest Add Contest Statistic LOGOUT playboy307 UPDATE POJ - 3624 Charm Bracelet ...

  8. 【TYVJ1936】【Clover杯NOIP模拟赛IV】太空战队

    [问题描述] 在社会经济高速发展的今天,借助高科技手段,组建太空战队的愿望就快实现了. 战队属下有N个航天员.作为空军选拔上来的佼佼者,每个航天员都有与生俱来的骄傲——他们每个人都认为自己是最强的或者 ...

  9. javascript中构造函数知识总结

    构造函数的说明 1.1 构造函数是一个模板 构造函数,是一种函数,主要用来在创建对象时对 对象 进行初始化(即为对象成员变量赋初始值),并且总是与new运算符一起使用. 1.2 new 运算符 new ...

  10. Retrofit进行post提交json数据

    1:先看一看xutils3的提交代码 String account = editText1.getText().toString(); String password = editText2.getT ...