hdu2888 二维RMQ
Check Corners
Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2513 Accepted Submission(s): 904
For each test case, the first line contains two integers m, n (1 <= m, n <= 300), which is the size of the row and column of the matrix, respectively. The next m lines with n integers each gives the elements of the matrix which fit in non-negative 32-bit integer.
The next line contains a single integer Q (1 <= Q <= 1,000,000), the number of queries. The next Q lines give one query on each line, with four integers r1, c1, r2, c2 (1 <= r1 <= r2 <= m, 1 <= c1 <= c2 <= n), which are the indices of the upper-left corner and lower-right corner of the sub-matrix in question.
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1000000001
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
//#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
int a[MAXN][MAXN],n,m,dp[MAXN][MAXN][][];
void Init()
{
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
dp[i][j][][] = a[i][j];
}
}
for(int pi = ; pi < ; pi++){
for(int pj = ; pj < ; pj++){
if(pi == && pj == )continue;
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
if(i + ( << pi) - > n || j + ( << pj) - > m)continue;
if(pi == ){
dp[i][j][pi][pj] = max(dp[i][j][pi][pj-],dp[i][j+(<<(pj-))][pi][pj-]);
}
else {
dp[i][j][pi][pj] = max(dp[i][j][pi-][pj],dp[i+(<<(pi-))][j][pi-][pj]);
}
}
}
}
}
}
void getans(int x1,int y1,int x2,int y2)
{
int kx,ky;
kx = (int)(log((double)(x2 - x1)) / log(2.0));
ky = (int)(log((double)(y2 - y1)) / log(2.0));
int ans = -INF;
ans = max(ans,dp[x1][y1][kx][ky]);
ans = max(ans,dp[x2 - ( << kx) + ][y1][kx][ky]);
ans = max(ans,dp[x1][y2 - ( << ky) + ][kx][ky]);
ans = max(ans,dp[x2 - ( << kx) + ][y2 - ( << ky) + ][kx][ky]);
printf("%d ",ans);
if(a[x1][y1] == ans || a[x1][y2] == ans || a[x2][y1] == ans || a[x2][y2] == ans)printf("yes\n");
else printf("no\n");
}
void solve()
{
int q;
scanf("%d",&q);
int x1,y1,x2,y2;
while(q--){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
getans(x1,y1,x2,y2);
}
}
int main()
{
while(~scanf("%d%d",&n,&m)){
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
scanf("%d",&a[i][j]);
}
}
Init();
solve();
}
return ;
}
hdu2888 二维RMQ的更多相关文章
- hdu2888 二维ST表(RMQ)
二维RMQ其实和一维差不太多,但是dp时要用四维 /* 二维rmq */ #include<iostream> #include<cstring> #include<cs ...
- HDU2888 Check Corners(二维RMQ)
有一个矩阵,每次查询一个子矩阵,判断这个子矩阵的最大值是不是在这个子矩阵的四个角上 裸的二维RMQ #pragma comment(linker, "/STACK:1677721600&qu ...
- hduacm 2888 ----二维rmq
http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题 直接用二维rmq 读入数据时比较坑爹 cin 会超时 #include <cstdio& ...
- hdu 2888 二维RMQ模板题
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2888 Check Corners (模板题)【二维RMQ】
<题目链接> <转载于 >>> > 题目大意: 给出一个N*M的矩阵,并且给出该矩阵上每个点对应的值,再进行Q次询问,每次询问给出代询问子矩阵的左上顶点和右下 ...
- POJ 2019 Cornfields [二维RMQ]
题目传送门 Cornfields Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7963 Accepted: 3822 ...
- 【LightOJ 1081】Square Queries(二维RMQ降维)
Little Tommy is playing a game. The game is played on a 2D N x N grid. There is an integer in each c ...
- 【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 ...
- POJ 2019 Cornfields (二维RMQ)
Cornfields Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4911 Accepted: 2392 Descri ...
随机推荐
- 学生管理系统<分层开发>
一:分层架构 搭建DAL层(数据访问层).UI层(表示层).BLL层(业务逻辑层)以及Model层(实体层) 各层的引用关系: DAL.UI.BLL层引用Model层 UI层引用BLL层 BLL层引用 ...
- vs2015产品密钥
HM6NR-QXX7C-DFW2Y-8B82K-WTYJV 博主验证有效
- marquee标签、插入百度地图
marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee标记不仅可以移动文字,也可以移动图片,表格等. 语法:<marquee>... ...
- avalon.js路由
之前自己写了一个AJAX加载页面的方法:有时候一个页面里面会分区域加载不同的东西(div,html),但是IE的回退按钮,就失去任何意义了: 这两天研究了一下avalon.js的路由: 需要准备: 1 ...
- listview1
Edit1.Text := listview1.Items[i].Caption; //读第i行第1列 Edit2.Text := listview1.Items[i].SubItems.string ...
- 微软职位内部推荐-SW Engineer II for Cloud Service
微软近期Open的职位: Positions: SDE for Big Data Cloud Services Azure Big Data Cloud Services and Cosmos are ...
- Java7并发编程实战(一) 线程的管理
1:线程的创建 1:继承Thread类,并且覆盖run()方法 2:创建一个实现Runnable接口的类.使用带参数的Thread构造器来构造 2:example-->计算打印乘法表 首先 ...
- CentOS 7下的 Mysql 主从配置
最近在玩mysql主从配置,在此记录一下 一.前言 1.安装两个虚拟机(CentOS 7).iP分别是192.168.47.131 和192.168.47.133.其中192.168.47.133作为 ...
- DTCMS插件的制作实例电子资源管理(一)插件目录结构
总目录 插件目录结构(一) Admin后台页面编写(二) 前台模板页编写(三) URL重写(四) 本实例旨在以一个实际的项目中的例子来介绍如何在dtcms中制作插件,本系列文章非入门教程,部分 ...
- jQuery操作单选按钮(radio)用法
1.获取选中值,四种方法都可以: $('input:radio:checked').val():$("input[type='radio']:checked").val(); $( ...