Codeforces Round #371 (Div. 1) D - Animals and Puzzle 二维ST表 + 二分
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>
#define ull unsigned long long
using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; int a[N][N], b[N][N], Log[N], n, m; struct ST2 {
int dp[N][N][][], ty;
void build(int n, int m, int b[N][N], int _ty) {
ty = _ty;
for(int i = ; i <= n; i++)
for(int j = ; j <= m; j++)
dp[i][j][][] = ty * b[i][j];
for(int u = ; u <= Log[n]; u++) {
for(int v = ; v <= Log[m]; v++) {
if(!u && !v) continue;
for(int i = ; i+(<<u)- <= n; i++) {
for(int j = ; j+(<<v)- <= m; j++) {
if(u) dp[i][j][u][v] = max(dp[i][j][u-][v], dp[i+(<<(u-))][j][u-][v]);
else dp[i][j][u][v] = max(dp[i][j][u][v-], dp[i][j+(<<(v-))][u][v-]);
}
}
}
}
}
int query(int x1, int y1, int x2, int y2) {
int k1 = Log[x2-x1+], k2 = Log[y2-y1+];
x2 = x2-(<<k1)+;
y2 = y2-(<<k2)+;
return max(max(dp[x1][y1][k1][k2], dp[x2][y1][k1][k2]),
max(dp[x1][y2][k1][k2], dp[x2][y2][k1][k2]));
}
} rmq; int main() {
for(int i = -(Log[]=-); i < N; i++)
Log[i] = Log[i - ] + ((i & (i - )) == ); scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++)
for(int j = ; j <= m; j++)
scanf("%d", &a[i][j]); for(int i = n; i >= ; i--) {
for(int j = m; j >= ; j--) {
if(!a[i][j]) continue;
b[i][j] = min(b[i+][j+], min(b[i][j+], b[i+][j])) + ;
}
} rmq.build(n, m, b, );
int q; scanf("%d", &q);
while(q--) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int l = , r = min(x2-x1, y2-y1) + , ans = ;
while(l <= r) {
int mid = l + r >> ;
int x3 = x2 - mid + , y3 = y2 - mid + ;
if(rmq.query(x1, y1, x3, y3) >= mid) l = mid + , ans = mid;
else r = mid - ;
}
printf("%d\n", ans);
}
return ;
} /*
*/
Codeforces Round #371 (Div. 1) D - Animals and Puzzle 二维ST表 + 二分的更多相关文章
- Codeforces Round #371 (Div. 1) D. Animals and Puzzle 二维倍增
D. Animals and Puzzle 题目连接: http://codeforces.com/contest/713/problem/D Description Owl Sonya gave a ...
- Codeforces 713D Animals and Puzzle(二维ST表+二分答案)
题目链接 Animals and Puzzle 题意 给出一个1e3 * 1e3的01矩阵,给出t个询问,每个询问形如x1,y1,x2,y2 你需要回答在以$(x1, y1)$为左上角,$(x1, ...
- Codeforces Round #198 (Div. 1) D. Iahub and Xors 二维树状数组*
D. Iahub and Xors Iahub does not like background stories, so he'll tell you exactly what this prob ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(分形)
E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【CodeForces】713 D. Animals and Puzzle 动态规划+二维ST表
[题目]D. Animals and Puzzle [题意]给定n*m的01矩阵,Q次询问某个子矩阵内的最大正方形全1子矩阵边长.n,m<=1000,Q<=10^6. [算法]动态规划DP ...
- Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...
- Codeforces Round #371 (Div. 2)B. Filya and Homework
题目链接:http://codeforces.com/problemset/problem/714/B 题目大意: 第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x ...
- Codeforces Round #371 (Div. 2) - B
题目链接:http://codeforces.com/contest/714/problem/B 题意:给定一个长度为N的初始序列,然后问是否能找到一个值x,然后使得序列的每个元素+x/-x/不变,最 ...
随机推荐
- mysql database 格式的查看和改变
MySQL中,数据库的编码是一个相当重要的问题,有时候我们需要查看一下当前数据库的编码,甚至需要修改一下数据库编码. 查看当前数据库编码的SQL语句为: mysql> use xxx Datab ...
- linux 版本查询
原文 : http://www.ha97.com/2987.html 一.查看Linux内核版本命令(两种方法): 1.cat /proc/version [root@localhost ~]# ca ...
- 题解 P4092 【[HEOI2016/TJOI2016]树】
参考了皎月半洒花的博客 看到树想到树剖,由于要取距自己到根离自己最近的标记点,刚开始想到线段树里存节点深度,查询时返回最大值.但是这样的话只能得到节点深度,无法得知节点编号,就想倍增乱搞一下,求出标记 ...
- linux内核支持nfs挂载配置
1.配置网络部分,主要是使能CONFIG_IP_PNP以在2中能够看到Root file system on NFS选项Networking support Networking options TC ...
- Android 加载网络图片设置到ImageView
下载图片后显示在ImageView中 //1.定义全局变量 private Handler handler; private String image_url; private Bitmap bitm ...
- Codeforces 620C EDU C.Pearls in a Row ( set + greed )
C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from ...
- sklearn中的model_selection模块(1)
sklearn作为Python的强大机器学习包,model_selection模块是其重要的一个模块: 1.model_selection.cross_validation: (1)分数,和交叉验证分 ...
- 12款jQuery幻灯片插件和幻灯片特效教程
jQuery 使用简单灵活,同时还有许多成熟的插件可供选择,它可以帮助你在项目中加入一些非常好的效果.滑块和幻灯片效果是常用的内容展示方式之一,这是一种在有限的网页空间内展示系列项目时非常好的方法.今 ...
- angular 开发之proxy
创建proxy配置文件proxy.conf.json 内容如下 { "/api/*": { "target": "https://abc.com ...
- JavaScript:自动生成博文目录导航
感谢 孤傲苍狼 分享了 自动生成博文目录的方法,本文仅作存档使用. 图 1:效果预览 CSS 样式 #TOCbar{ font-size:12px; text-align:left; position ...