HDU2888 Check Corners(二维RMQ)

时间:2022-08-30 14:44:17

有一个矩阵,每次查询一个子矩阵,判断这个子矩阵的最大值是不是在这个子矩阵的四个角上

裸的二维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)的更多相关文章

  1. HDU-2888 Check Corners 二维RMQ

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题.解题思路如下(转载别人写的): dp[row][col][i][j] 表示[row,ro ...

  2. Hdu 2888 Check Corners &lpar;二维RMQ &lpar;ST&rpar;&rpar;

    题目链接: Hdu 2888 Check Corners 题目描述: 给出一个n*m的矩阵,问以(r1,c1)为左上角,(r2,c2)为右下角的子矩阵中最大的元素值是否为子矩阵的顶点? 解题思路: 二 ...

  3. 【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 ...

  4. HDU 2888:Check Corners(二维RMQ)

    http://acm.hdu.edu.cn/showproblem.php?pid=2888 题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中 ...

  5. HDU 2888 Check Corners &lpar;模板题&rpar;【二维RMQ】

    <题目链接> <转载于 >>> > 题目大意: 给出一个N*M的矩阵,并且给出该矩阵上每个点对应的值,再进行Q次询问,每次询问给出代询问子矩阵的左上顶点和右下 ...

  6. hdu2888 二维RMQ

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  7. HDU2888 Check Corners

    Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numbers ( 1 ...

  8. hdu 2888 二维RMQ模板题

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  9. hdu 2888 二维RMQ

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. Asp&period;Net MVC&plus;BootStrap&plus;EF6&period;0实现简单的用户角色权限管理

    这是本人第一次写,写的不好的地方还忘包含.写这个的主要原因是想通过这个来学习下EF的CodeFirst模式,本来也想用AngularJs来玩玩的,但是自己只会普通的绑定,对指令这些不是很熟悉,所以就基 ...

  2. asp&period;net解决高并发的方案&period;&lbrack;转&rsqb;

    最近几天一直在读代震军的博客,他是Discuz!NT的设计者,读了他的一系列关于Discuz!NT的架构设计文章,大呼过瘾,特别是Discuz!NT在解决高访问高并发时所设计的一系列方案,本人尤其感兴 ...

  3. 谈 IIS7&period;5 Asp&period;Net模拟用户

    IIS  Asp.模拟用户官方的解释是: 如果要在非默认安全上下文中运行 ASP.NET 应用程序,请使用 ASP.NET 模拟身份验证. 如果您对某个 ASP.NET 应用程序启用了模拟,那么该应用 ...

  4. 使用Sublime Text 2编辑和运行node-webkit应用程序

    开发工具目录结构 --E:\develop\ ----node-webkit-v0.9.2-win-ia32 ----Sublime Text 2.0.2 x64 为Sublime text2构建Bu ...

  5. 再议 js 数字格式之正则表达式

    原文:再议 js 数字格式之正则表达式 前面我们提到到了js的数字格式<浅谈 js 数字格式类型>,之前的<js 正则练习之语法高亮>里也提到了优化数字匹配的正则.不过最近落叶 ...

  6. 201521123114 《Java程序设计》第2周学习总结

    #1. 本周学习总结 1. 学会了使用码云管理代码,使用eclipse关联jdk源代码: 2. 学习了包管理机制,包的作用:主要是管理java文件,解决同名文件冲突; 3. ArrayList可以处理 ...

  7. Java 对象复制

    Java 对象的一共有 3 种复制对象的方式. 1.直接赋值 (引用复制 ),此种复制方式比较常用. 诸如 A  a = b ;  a 是直接复制了b的引用 ,也就是说它俩指向的是同一个对象. 此时 ...

  8. SQL2008 一直error40 无法连接到localhost

    1. Problem 2. Reason 可能是之前卸载SQL Server时没卸载干净 后来又重新安装时导致默认实例名不能用 就随手写了个SQLMOLORY实例名 但其实系统内这时是有两个SQL实例 ...

  9. 伪静态与重定向--RewriteBase

    RewriteBase用于设置目录级重写的基准URL,即所有的重定向都是基于这个URL.内部重定向可能看不出效果,但是在外部重定向(使用R flag后),如果不手动指定 / 为根目录,那么就会去整个磁 ...

  10. 关于Unity中NGUI的Tab商城、Scrollview和打字机效果的实现

    Tab商城实例 UIToggle 和 UIToggledObjects+ Box Collider(实现商城功能必备) 1.创建两个个UI Sprite,Sprite1和Sprite2 2.给Spri ...