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

裸的二维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 (二维RMQ (ST))

    题目链接: 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 (模板题)【二维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. 27Tcp文件传输

    前面介绍了TCP和UDP的通信,只是文体通信,只能传送文字.本次介绍文件传输,也就是文件读写和TCP通信的结合. 解析:根据之前的TCP通信,建立彼此的连接.服务器选择文件,首先将文件的基本信息发送给 ...

  2. CCPC 2017-2018, Finals Solution

    A - Dogs and Cages 水. #include <bits/stdc++.h> using namespace std; int t; double n; int main( ...

  3. javascript日期字符串和日期对象相互转换

    HTML页面间需要传递日期和时间参数的时候,如果需要对日期字符串进行时间的运算,就需要先将日期字符串转换成JS日期对象. 在js中,yyyy-MM-dd HH:mm:ss格式的日期字符串不能用来直接构 ...

  4. PHImageManager 获取图片模糊

    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.synchronous = true; o ...

  5. 前端学习笔记之CSS后代选择器、子元素选择器、相邻兄弟选择器区别与详解

    派生选择器用的很多,派生选择器具体包括为后代选择器.子元素选择器.相邻兄弟选择器,我们来理解一下他们之间的具体用法与区别. 1.css后代选择器语法:h1 em {color:red;} 表示的是从h ...

  6. MySQL "java.lang.IllegalArgumentException: HOUR_OF_DAY: 2 -> 3" 问题解析

    抛出异常截图: 异常原因 系统时区原因. 解决办法 在数据库连接串加上 &serverTimezone=Asia/Shanghai 即可~ conn_str="jdbc:mysql: ...

  7. SDN前瞻 该来的来了!SDN 软件定义网络

    SDDC:Software Defined Data Center 软件定义数据中心,全数据中心软件化. 在我们接触SDN概念之前,服务器虚拟化,软件虚拟化技术已经是非常成熟了.如果网络能够被虚拟化, ...

  8. UVa 10054 项链(欧拉回路)

    https://vjudge.net/problem/UVA-10054 题意:有一种由彩色珠子连接成的项链.每个珠子的两半由不同颜色组成.相邻两个珠子在接触的地方颜色相同.现在有一些零碎的珠子,需要 ...

  9. 利用JS将页面中包含“一个”字段值的元素改为红色

    document.body.innerHTML = document.body.innerHTML.replace(/一个/ig,"<span style='color: red;'& ...

  10. python json与字典对象互相转换

    改文章转自:https://www.cnblogs.com/Lin-Yi/p/7640147.html 1 import requests 2 import json 3 ''' 4 json.loa ...