HDU2888 Check Corners(二维RMQ)
有一个矩阵,每次查询一个子矩阵,判断这个子矩阵的最大值是不是在这个子矩阵的四个角上
裸的二维RMQ
#pragma comment(linker, "/STACK:1677721600")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf (-((LL)1<<40))
#define lson k<<1, L, (L + R)>>1
#define rson k<<1|1, ((L + R)>>1) + 1, R
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define dec(i, a, b) for(int i = a; i >= b; i --) template<class T> T MAX(T a, T b) { return a > b ? a : b; }
template<class T> T MIN(T a, T b) { return a < b ? a : b; }
template<class T> T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
template<class T> T LCM(T a, T b) { return a / GCD(a,b) * b; } //typedef __int64 LL;
typedef long long LL;
const int MAXN = + ;
const int MAXM = ;
const double eps = 1e-;
LL MOD = ; int m, n;
int mx[][][][];
int idx[], q, lx, ly, rx, ry; void rmq_init(int m, int n) {
for(int i = ; (<<i) <= m; i ++) {
for(int j = ; (<<j) <= n; j ++) {
if(i == && j == ) continue;
int len2 = ( << j), len1 = ( << i);
for(int x = ; x + len1 - <= m; x ++) {
for(int y = ; y + len2 - <= n; y ++) {
if(i == ) mx[x][i][y][j] = max(mx[x][i][y][j - ], mx[x][i][y + (len2 >> )][j - ]);
else mx[x][i][y][j] = max(mx[x][i - ][y][j], mx[x + (len1 >> )][i - ][y][j]);
}
}
}
}
for(int i = ; i <= m || i <= n; i ++) {
idx[i] = ;
while(( << (idx[i] + )) <= i) idx[i] ++;
}
} int rmq(int lx, int rx, int ly, int ry) {
int a = idx[rx - lx + ], la = ( << a);
int b = idx[ry - ly + ], lb = ( << b);
return max(max(max(mx[lx][a][ly][b],
mx[rx - la + ][a][ly][b]),
mx[lx][a][ry - lb + ][b]),
mx[rx - la + ][a][ry - lb + ][b]);
} int main()
{
//FIN;
while(~scanf("%d %d", &m, &n)) {
mem0(mx);
rep (i, , m) rep (j, , n)
scanf("%d", &mx[i][][j][]);
rmq_init(m, n);
scanf("%d", &q);
while(q--) {
scanf("%d %d %d %d", &lx, &ly, &rx, &ry);
int ma = rmq(lx, rx, ly, ry);
printf("%d %s\n", ma, ma == mx[lx][][ly][] || ma == mx[lx][][ry][]
|| ma == mx[rx][][ly][] || ma == mx[rx][][ry][]
? "yes" : "no");
}
}
return ;
}
HDU2888 Check Corners(二维RMQ)的更多相关文章
- HDU-2888 Check Corners 二维RMQ
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题.解题思路如下(转载别人写的): dp[row][col][i][j] 表示[row,ro ...
- Hdu 2888 Check Corners (二维RMQ (ST))
题目链接: Hdu 2888 Check Corners 题目描述: 给出一个n*m的矩阵,问以(r1,c1)为左上角,(r2,c2)为右下角的子矩阵中最大的元素值是否为子矩阵的顶点? 解题思路: 二 ...
- 【HDOJ 2888】Check Corners(裸二维RMQ)
Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numb ...
- HDU 2888:Check Corners(二维RMQ)
http://acm.hdu.edu.cn/showproblem.php?pid=2888 题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中 ...
- HDU 2888 Check Corners (模板题)【二维RMQ】
<题目链接> <转载于 >>> > 题目大意: 给出一个N*M的矩阵,并且给出该矩阵上每个点对应的值,再进行Q次询问,每次询问给出代询问子矩阵的左上顶点和右下 ...
- hdu2888 二维RMQ
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU2888 Check Corners
Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numbers ( 1 ...
- hdu 2888 二维RMQ模板题
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 2888 二维RMQ
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- VS2010/MFC编程入门之十三(对话框:属性页对话框及相关类的介绍)
前面讲了模态对话框和非模态对话框,本节开始鸡啄米讲一种特殊的对话框--属性页对话框.另外,本套教程所讲大部分对VC++各个版本均可适用或者稍作修改即可,但考虑到终究还是基于VS2010版本的,所以将& ...
- 2017 Benelux Algorithm Programming Contest (BAPC 17) Solution
A - Amsterdam Distance 题意:极坐标系,给出两个点,求最短距离 思路:只有两种方式,取min 第一种,先走到0点,再走到终点 第二种,走到同一半径,再走过去 #include ...
- 2017-2018 ACM-ICPC Latin American Regional Programming Contest Solution
A - Arranging tiles 留坑. B - Buggy ICPC 题意:给出一个字符串,然后有两条规则,如果打出一个辅音字母,直接接在原字符串后面,如果打出一个元音字母,那么接在原来的字符 ...
- iOS error: -34018
一般报这个错误是由于操作keychain 报的错. 遇到该情况的情况: 1.是否打开权限 2.苹果自身的bug,传送门:https://stackoverflow.com/questions/2974 ...
- bzoj1610 / P2665 [USACO08FEB]连线游戏Game of Lines
P2665 [USACO08FEB]连线游戏Game of Lines 第一次写快读没判负数....(捂脸) 暴力$O(n^2)$求斜率,排序判重. 注意垂直方向的直线要特判. end. #inclu ...
- JAVA面试题整理(5)-数据库
数据库 1.Oracle/mysql分页有什么优化 2.悲观锁.乐观锁 悲观锁(Pessimistic Concurrency Control,PCC):假定会发生并发冲突,屏蔽一切可能违反数据完整性 ...
- Mininet 跑一个简单的ping测试
安装地址:https://github.com/mininet/mininet/wiki/Mininet-VM-Images 登录用户:mininet 密码:mininet 执行命令:sudo mn ...
- Vue.js的类Class 与属性 Style如何绑定
Vue.js的类Class 与属性 Style如何绑定 一.总结 一句话总结:数据绑定一个常见需求是操作元素的 class 列表和它的内联样式.因为它们都是属性,我们可以用 v-bind 处理它们:我 ...
- gitlab访问限制问题------Forbidden
解决方案: cd /etc/gitlab vim /gitlab.rb gitlab_rails['rack_attack_git_basic_auth'] = { 'enabled' => t ...
- poj1087最大流拆点
刚开始看这题太长了就放着,后来做了之后才发现并不难,就是构造图有点麻烦 一开始写了180行@.@结果tle了,后来想到用map直接访问的话可能会快点,就不用每次循环了 #include<map& ...