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

裸的二维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. 26. Remove Duplicates from Sorted Array(删除排序数组中的重复元素,利用排序的特性,比较大小)

      Given a sorted array, remove the duplicates in-place such that each element appear only once and r ...

  2. AtCoder Grand Contest 029 Solution

    A: Solved. 签. #include <bits/stdc++.h> using namespace std; #define ll long long #define N 200 ...

  3. react 修改循环列表的当前单个子项状态:思路 拿原始state数据更改,再做请求

    handleLike(item,index){ var id = item.id; _ENV.post( _ENV.HOST+'/communion/video-up', {'user_id':loc ...

  4. POI之Excel导出

    1,在maven的pom文件中添加依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId& ...

  5. 模块的封装之C语言类的封装

    [微知识]模块的封装(一):C语言类的封装 是的,你没有看错,我们要讨论的是C语言而不是C++语言中类的封装.在展开知识点之前,我首先要 重申两点: 1.面向对象是一种思想,基本与所用的语言是无关的. ...

  6. 为pyhon安装opencv扩展包出现distributed 1.21.8 requires msgpack, which is not installed.【转】

    本文转载自:https://blog.csdn.net/weixin_39513374/article/details/81051466 pip install msgpack-python pip ...

  7. UVA 257 Palinwords(hash)题解

    思路:给你字符串,如果他包含至少两个长度大于等于3的回文,并且这些回文不能嵌套(例如aaa嵌套在aaaa,waw嵌套在awawa),如果这个字符串这么牛逼的话,就输出他. 思路:拿到字符串先正序has ...

  8. BloomFilter–大规模数据处理利器

    转自: http://www.dbafree.net/?p=36 BloomFilter–大规模数据处理利器 Bloom Filter是由Bloom在1970年提出的一种多哈希函数映射的快速查找算法. ...

  9. Solidity 官方文档中文版 1_简介

    简介 Solidity是一种语法类似JavaScript的高级语言.它被设计成以编译的方式生成以太坊虚拟机代码.在后续内容中你将会发现,使用它很容易创建用于投票.众筹.封闭拍卖.多重签名钱包等等的合约 ...

  10. IOS-static cell 与 dynamic cell 混合使用

    static cell 与 dynamic cell 混合使用 关于静态cell与动态cell的混合使用,google一下便会有很多相关文章,这里也是看过一些前辈的经验(已经忘记具体是从哪篇文章得到的 ...