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

【题意】

在这里输入题意

【题解】

找个规律会发现
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. [Wikioi 1226]倒水问题

    题目描写叙述 Description 有两个无刻度标志的水壶.分别可装 x 升和 y 升 ( x,y 为整数且均不大于 100 )的水. 设另有一水 缸,可用来向水壶灌水或接从水壶中倒出的水, 两水壶 ...

  2. mysql查询count

    Every derived table must have its own alias 每个派生出来的表都必须有一个自己的别名 一般在多表查询时,会出现此错误. 因为,进行嵌套查询的时候子查询出来的的 ...

  3. Tomcat报错合集

    1.java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start c ...

  4. 屏幕測试亮点,新买了一个显示器,使用web简单的測试下了亮点

    1,购买了一个新的显示器 趁着双11的时候价格廉价.入手了一个显示器. http://serve.netsh.org/pub/dead_pixel.bin 滚动下就能够换颜色了.把chrome最大化, ...

  5. Truck History --hdoj

    Truck History Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tota ...

  6. 智能识别收货地址 javascript

    欢迎加入前端交流群交流知识&&获取视频资料:749539640 地址: https://github.com/wzc570738205/smart_parse

  7. Spark Streaming概念学习系列之Spark Streaming容错

    Spark Streaming容错 检查点机制-checkpoint 什么是检查点机制? Spark Streaming 周期性地把应用数据存储到诸如HDFS 或Amazon S3 这样的可靠存储系统 ...

  8. C#中大批量导入数据SqlBulkCopy

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  9. [hihocoder][Offer收割]编程练习赛49

    相似颜色 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #includ ...

  10. vue2.0.js

     数据的渲染.数据同步  组件化.模块化 路由    ajax  数据流 Vue.js学习资源        中文官网:http://cn.vuejs.org/             源码:http ...