考试yy二维ST表失败导致爆零。

其实和一维的ST表很像...

也是设$f[i][j][p][q]$为以$(i, j)$为左上角,长为$2^p$,宽为$2^q$的矩形的最大值。

算法流程是先把每一行都分别求一遍一维的ST表,然后再把行与行之间合并...

查询和一维ST表类似

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define reg register
inline int read() {
int res=;char ch=getchar();bool fu=;
while(!isdigit(ch))fu|=(ch=='-'),ch=getchar();
while(isdigit(ch))res=(res<<)+(res<<)+(ch^),ch=getchar();
return fu?-res:res;
} int n, m;
int a[][];
int st[][][][]; inline int query(int x1, int y1, int x2, int y2)
{
int k1 = log2(x2 - x1 + ), k2 = log2(y2 - y1 + );
return max(st[x1][y1][k1][k2], max(st[x2-(<<k1)+][y1][k1][k2], max(st[x1][y2-(<<k2)+][k1][k2], st[x2-(<<k1)+][y2-(<<k2)+][k1][k2])));
} int main()
{
freopen("yy.in", "r", stdin);
freopen("yy.out", "w", stdout);
n = read(), m = read();
for (reg int i = ; i <= n ; ++i)
for (reg int j = ; j <= m ; ++j)
st[i][j][][] = a[i][j] = read();
for (reg int p = ; p <= ; p ++)
for (reg int q = ; q <= ; q ++)
if (p != or q != )
for (reg int i = ; i + (<<p) - <= n ; i ++)
for (reg int j = ; j + (<<q) - <= m ; j ++)
if (!p) st[i][j][p][q] = max(st[i][j][p][q - ], st[i][j+(<<(q-))][p][q - ]);
else st[i][j][p][q] = max(st[i][j][p-][q], st[i+(<<(p-))][j][p-][q]);
int q = read();
while(q--)
{
int x1=read(),y1=read(),x2=read(),y2=read();
printf("%d\n", query(x1,y1,x2,y2));
}
return ;
}

最新文章

  1. Python基础篇【第7篇】: 面向对象(1)
  2. jdbc autoReconnect=true 参数设置导致 slow log 爆表。
  3. Iphone 英语语言下通讯录排序问题
  4. 高大上的uGUI正式版发布了
  5. UML 简单介绍
  6. 【小月博客】用HTML5的File API做上传图片预览功能
  7. mysql 错误代码汇总
  8. 01-03-03【Nhibernate (版本3.3.1.4000) 出入江湖】cascade的测试
  9. H - 高桥和低桥
  10. MySQL查询优化处理
  11. 【Python】Coding the Matrix:Week 5: Dimension Homework 5
  12. Swift语言iOS8的蓝牙Bluetooth解析
  13. 悬浮二维码 QQ ToTop
  14. JedisConnectionException: Unexpected end of stream.
  15. (cljs/run-at (JSVM. :all) &quot;一次说白DataType、Record和Protocol&quot;)
  16. 201521123108 《Java程序设计》第6周学习总结
  17. javscript eval()的优缺点与web安全防范
  18. 图片转base64上传,视频同理。
  19. jupyter Notebook环境搭建
  20. C#-vs2012学习笔记-惊奇于vs的强大和便利

热门文章

  1. apache ignite系列(三):数据处理(数据加载,数据并置,数据查询)
  2. Elastic Stack 笔记(六)Elasticsearch5.6 搜索详解
  3. caffe学习三:使用Faster RCNN训练自己的数据
  4. Git同步更新操作GitHub和码云仓库上面的代码
  5. PopUpWindow 的使用笔记
  6. uboot学习之BL3的流程
  7. Java优化策略小积累
  8. opencv调整图像亮度对比度
  9. css或Angular框架限制文本字数
  10. Spring Environment的加载