博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu多校第4场E. Matrix from Arrays HDU 二维前缀和
阅读量:5152 次
发布时间:2019-06-13

本文共 2327 字,大约阅读时间需要 7 分钟。

Problem E. Matrix from ArraysTime Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 907    Accepted Submission(s): 403Problem DescriptionKazari 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. InputThe first line of the input contains an integer T (1≤T≤100) denoting the number of test cases.Each test case starts with an integer L (1≤L≤10) denoting the length of A.The second line contains L integers A0,A1,...,AL−1 (1≤Ai≤100).The third line contains an integer Q (1≤Q≤100) denoting the number of queries.Each of next Q lines consists of four integers x0,y0,x1,y1 (0≤x0≤x1≤108,0≤y0≤y1≤108) querying the sum over the sub matrix whose upper-leftmost cell is (x0,y0) and lower-rightest cell is (x1,y1). OutputFor each test case, print an integer representing the sum over the specific sub matrix for each query. Sample Input1        3        1 10 1005        3 3 3 32 3 3 32 3 5 85 1 10 109 99 999 1000 Sample Output11011068223833076541 Source2018 Multi-University Training Contest 4 Recommendchendu   |   We have carefully selected several similar problems for you:  6343 6342 6341 6340 6339

 

 

 

 

 

 

如图二 根据容斥原理S=S1-S2-S3+S4;;S1, S2, S3, S4都是以(x, y)为右下角,以(0, 0)为左上角的矩阵,问题就转化成了求这样的矩阵图一;

米黄色的面积表示有多少个完整的循环矩阵,下方白条及右方白条表示只有长或宽不完整的矩阵,橙黄色面积表示不完整的循环矩阵;

 

#include
#include
#include
using namespace std;#define ll long longll m[100][100];ll a[100000];ll sum[25][25];ll len;ll jisuan(int x,int y){ ll ans=(x/len)*(y/len)*sum[len][len];//多少个重复规律 ans+=sum[x%len][len]*(y/len)+sum[len][y%len]*(x/len);//左边和下面 ans+=sum[x%len][y%len];//左下角 return ans;}int main(){ int T; scanf("%d",&T); while(T--) { int l; scanf("%d",&l); for(int i=0;i

 

转载于:https://www.cnblogs.com/2014slx/p/9409669.html

你可能感兴趣的文章
WPF Uri
查看>>
android 获取IMEI号
查看>>
【设计模式】—— 外观模式Facade
查看>>
Log4j官方文档翻译(六、日志的级别)
查看>>
JSON定义
查看>>
你不知道的JavaScript之类型
查看>>
工作流,sharepoint 开发流程
查看>>
[转]Android推送方案分析(MQTT/XMPP/GCM)
查看>>
使用方向变换(directional transform)图像分块压缩感知
查看>>
朴素贝叶斯法
查看>>
YCbCr-YUV
查看>>
Win10 + MySQL + Tableu + PPT + 可视化方案
查看>>
vs2010+qt4编译出现error LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject等错误...
查看>>
css权威指南学习笔记 —— css选择器
查看>>
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
查看>>
JS实现动态添加和删除div
查看>>
(转载)MySQL中UNION和UNION ALL的使用
查看>>
Visual Studio Code Angular4 配置环境
查看>>
Linux 学习碎片
查看>>
if else语句
查看>>