求N维前缀和】的更多相关文章

转载自http://blog.csdn.net/jzhang1/article/details/50528549#comments 膜拜 #include <iostream> #include <cstring> #include <cstdlib> #include <string> #include <cstdio> #include <algorithm> #include <cmath> #include <…
我们知道,数组上的前缀和S[i]=S[i-1]+a[i] 那么,怎样求二维前缀和呢? 二维前缀和: 绿色点的前缀和就是黄色.红色.灰色和绿色的点权和 怎样计算? s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j]; 绿色部分的前缀和=(红色+灰色)+(黄色+灰色)-灰色+绿色 有了前缀和,怎样计算某一部分的点权和呢? 类似的,现在绿色部分的总和=S(4,4)-S(4,2)-S(2,4)+S(2,2) 我们设绿色部分的边长为rx*ry,a为总和,绿色部分…
http://acm.hdu.edu.cn/showproblem.php?pid=6514 Problem Description Xiaoteng has a large area of land for growing crops, and the land can be seen as a rectangle of n×m. But recently Xiaoteng found that his crops were often stolen by a group of people,…
题目链接: I. Special Squares There are some points and lines parellel to x-axis or y-axis on the plane. If arbitrary chosen two lines parallel to x-axis and two lines parallel to y-axis, one rectangle, or sometimes a square, will be formed. If a square i…
C. New Year and Domino   They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so. Limak is a little polar bear who loves to play. He has recently got a rectangular grid with h rows and…
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1218 题意概括 给出一个大的矩阵,求边长为r的正方形区域的最大sum. 题解 二维前缀和然后暴力就可以了. 代码 #include <cstring> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cmath> using namespace std; co…
链接:https://ac.nowcoder.com/acm/contest/317/E来源:牛客网 题目描述 小a正在玩一款即时战略游戏,现在他要用航空母舰对敌方阵地进行轰炸 地方阵地可以看做是n×mn×m的矩形 航空母舰总共会派出qq架飞机. 飞机有两种,第一种飞机会轰炸以(xi,yi)(xi,yi)为中心,对角线长为lili的正菱形(也就是两条对角线分别于xx轴 yy轴平行的正方形),而第二种飞机只会轰炸正菱形的上半部分(包括第xixi行) (具体看样例解释) 现在小a想知道所有格子被轰炸…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6336 Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1711    Accepted Submission(s): 794 Problem Description Kazari…
题意: for (int i = 0; ; ++i) { for (int j = 0; j <= i; ++j) { M[j][i - j] = A[cursor]; cursor = (cursor + 1) % L; }} 给定序列A[1..L],二维数组M的规律由以上代码给出.Q个查询,每次给x0,y0,x1,y1 (0≤x0≤x1≤1e8,0≤y0≤y1≤1e8)四个数,求以(x0,y0)和(x1,y1)两个点为端点的矩形中数的和. 分析:根据推导可得,M[i][j] = M[i+2L…
6336.Problem E. Matrix from Arrays 不想解释了,直接官方题解: 队友写了博客,我是水的他的代码 ------>HDU 6336 子矩阵求和 至于为什么是4倍的,因为这个矩阵是左上半边有数,所以开4倍才能保证求的矩阵区域里面有数,就是图上的红色阴影部分,蓝色为待求解矩阵. 其他的就是容斥原理用一下,其他的就没什么了. 代码: //1005-6336-矩阵求和-二维前缀和+容斥-预处理O(1)查询输出 #include<iostream> #include&…