poj 2019 二维RMQ

【PostgreSQL】Windows11下的PostgreSQL数据库安装tds_fdw扩展及使用(图文记录详细步骤) 【详解】【PostgreSQL】Windows11下的PostgreSQL数据库安装tds_fdw扩展及使用 阅读详情

Cornfields
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 6169 Accepted: 3039

Description

FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the cornfield on the flattest piece of land he can find. 

FJ has, at great expense, surveyed his square farm of N x N hectares (1 <= N <= 250). Each hectare has an integer elevation (0 <= elevation <= 250) associated with it. 

FJ will present your program with the elevations and a set of K (1 <= K <= 100,000) queries of the form "in this B x B submatrix, what is the maximum and minimum elevation?". The integer B (1 <= B <= N) is the size of one edge of the square cornfield and is a constant for every inquiry. Help FJ find the best place to put his cornfield. 

Input

* Line 1: Three space-separated integers: N, B, and K. 

* Lines 2..N+1: Each line contains N space-separated integers. Line 2 represents row 1; line 3 represents row 2, etc. The first integer on each line represents column 1; the second integer represents column 2; etc. 

* Lines N+2..N+K+1: Each line contains two space-separated integers representing a query. The first integer is the top row of the query; the second integer is the left column of the query. The integers are in the range 1..N-B+1. 

Output

* Lines 1..K: A single integer per line representing the difference between the max and the min in each query. 

Sample Input

5 3 1
5 1 2 6 3
1 3 5 2 7
7 2 4 6 1
9 9 8 6 5
0 6 9 3 9
1 2

Sample Output

5


/*
poj 2019 二维RMQ
前段时间不知道poj怎么了,现在补上
二维RMQ简单,求解区间最大最小值的差
hhh-2016-02-02 19:25:50
*/

#include <functional>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <Map>
using namespace std;
typedef long long ll;
typedef long double ld;

using namespace std;
const int maxn = 255;
int dp[maxn][maxn][8][8];
int dp1[maxn][maxn][8][8];
int tmap[maxn][maxn];
int mm[maxn];
void iniRMQ(int n,int m)
{
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            dp[i][j][0][0] = tmap[i][j];
            dp1[i][j][0][0] = tmap[i][j];
        }
    for(int ti = 0; ti <= mm[n]; ti++)
        for(int tj = 0; tj <= mm[m]; tj++)
            if(ti+tj)
                for(int i = 1; i+(1<<ti)-1 <= n; i++)
                    for(int j = 1; j+(1<<tj)-1 <= m; j++)
                    {
                        if(ti)
                        {
                            dp[i][j][ti][tj] =
                                max(dp[i][j][ti-1][tj],dp[i+(1<<(ti-1))][j][ti-1][tj]);
                            dp1[i][j][ti][tj] =
                                min(dp1[i][j][ti-1][tj],dp1[i+(1<<(ti-1))][j][ti-1][tj]);

                        }
                        else
                        {
                            dp[i][j][ti][tj] =
                                max(dp[i][j][ti][tj-1],dp[i][j+(1<<(tj-1))][ti][tj-1]);
                            dp1[i][j][ti][tj] =
                                min(dp1[i][j][ti][tj-1],dp1[i][j+(1<<(tj-1))][ti][tj-1]);
                        }
                    }
}

int RMQ(int x1,int y1,int x2,int y2)
{
    int k1 = mm[x2-x1+1];
    int k2 = mm[y2-y1+1];
    x2 = x2 - (1<<k1) +1;
    y2 = y2 - (1<<k2) +1;
    return
        max(max(dp[x1][y1][k1][k2],dp[x1][y2][k1][k2]),
            max(dp[x2][y1][k1][k2],dp[x2][y2][k1][k2])) -
        min(min(dp1[x1][y1][k1][k2],dp1[x1][y2][k1][k2]),
            min(dp1[x2][y1][k1][k2],dp1[x2][y2][k1][k2]));
}

int main()
{
    int a,b,n,m,k;
    mm[0] = -1;
    for(int i = 1;i < 255;i++)
    {
        mm[i] = (i&(i-1)) == 0 ? mm[i-1]+1:mm[i-1];
    }
    while(scanf("%d%d%d",&n,&m,&k) != EOF)
    {
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
            {
                scanf("%d",&tmap[i][j]);
            }
        iniRMQ(n,n);
        while(k--)
        {
            scanf("%d%d",&a,&b);
            printf("%d\n",RMQ(a,b,a+m-1,b+m-1));
        }
    }
}



华为OD机试 - 开源项目热度榜单(Java 2025 C卷 100分) H = Wwatch X#watch + Wstar X#star +Wfork X#fork +Wissue X#issue +Wmr X#mr H表示热度值,Wwatch、Wstar、Wfork、Wissue、Wmr分别表示5个统计维度的权重,#watch、#star、#fork、#issue、#mr分别表示5个统计维度的统计值。 阅读详情

相关推荐

二次规划问题(qp)和序列二次规划问题(sqp)的简单理解

当二次规划的约束为非线性约束时,通常会采用sqp进行求解,用连续求解qp的方法来得到非线性约束条件下的最优解,上述的qpoases和osqp均无法直接求解非线性约束问题,所以如果使用这两个库的话,注意,sqp是结果,而不是原因,只有在非线性约束的情况下才会考虑sqp求解,如果问题本身就是线性约束,则直接用qp解就行。对于工程师而言,我们在编写代码的时候,并不关心二次规划问题的求解细节,所以一般是把二次规划问题建立好后,直接调用三方库进行求解。因为约束为非线性约束,所以先将约束进行线性化,约束原方程为。

zmhzmhzm的博客 1万+

每日一题----Cornfields--poj2019(附翻译和题解)

二维稀疏表

2201_75867204的博客 355

如何在软件复位后保留指定RAM区域的数据

本文主要介绍S32K144的RAM retention功能

北极熊的脖子(16605192620@163.com) 1万+

Cornfields(二维ST表模板)

FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he’s looking to build the cornfield on the flattest piece of land he can find. FJ has, at...

宇宙无敌大可爱CUU的博客 1342

LAMMPS实操系列(一): 大量FCC-CoCrCuFeNi高熵合金建模与最稳定结构筛选

高熵合金(High-entropy alloys,HEA),是由五种或五种以上等量或大约等量金属形成的合金。由于高熵合金可能具有许多优秀的物理化学性质,因此在材料科学领域受到广泛关注

Ceshigo_CD的博客 3257

华硕主板UEFI模式下安装Ubuntu与Windows双系统全攻略

本文详细讲解了在华硕主板UEFI模式下安装Ubuntu与Windows双系统的完整流程。从安装前的BIOS关键设置(如处理安全启动与CSM)、使用GPT分区表,到在Windows中安全分配空间、手动创建Ubuntu分区,最后完成引导配置,提供了避免常见错误的实用技巧,确保双系统稳定共存。

weixin_29199873的博客 345

POJ 2019 Cornfields(我的水题之路——多case??TLE??)

Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4034   Accepted: 1933 Description FJ has decided to grow his own corn hybrid in order to help th

1125

学Simulink——基于Simulink的扰动观测器(DOB)补偿坡道重力分量

(质量5kg,坡度30°,目标速度1m/s)为例,基于Simulink搭建“DOB+PI”复合控制仿真平台,从系统建模、DOB算法推导、离散化实现到Simulink模块搭建,提供模块化模型、核心代码及参数整定表,帮助工程师彻底解决重力等恒值扰动引起的稳态误差问题。采用双线性变换(Tustin): s=Ts​2​z+1z−1​,其中 Ts​为控制周期。模块相加(注意符号:ufinal​=upi​−ucomp​或 upi​+ucomp​,取决于扰动定义方向,此处假设重力为正,控制力需反向抵消,故为减)。

MHD0815的博客 69

POJ-2019——Cornfields(二维RMQ?暴力吧!)

题意:给你一个N*N的矩阵,每一个点有一个权值,询问子矩阵中最大值与最小值的差 分析:感觉没啥好说的,这是一个显然的二维RMQ问题,把模版一套,AC!结果很奇怪的是这道题很水,暴力也可以过,真是见了鬼了! 二维ST算法 #include #include #include #include #include #include #include #include #includ

shengtao96的专栏 904

【Unity】【2D】用连续图片生成动画Animation的简明步骤

本文介绍了Unity中使用2D连续图片制作2D动画Animation的简明步骤。

O青草O的博客 Unity和游戏制作知识分享 718

YOLO26魔改神技:YOLO26引入SimAM(无参注意力):不增加网络参数的3D能量函数提点黑科技

文章摘要 2026年YOLO26模型发布引发边缘计算革命,但特定场景精度不足问题催生注意力机制改进需求。本文聚焦无参数注意力机制SimAM,基于神经科学理论通过3D能量函数直接计算神经元权重,实现零参数量提升模型性能。文章深度解析YOLO26四大创新架构,对比SimAM与传统注意力机制差异,并探讨其在YOLO26中的集成方案。研究显示,SimAM在不增加模型体积前提下显著提升mAP指标,特别适合边缘端部署。全文涵盖架构设计、代码实现、竞品对比、部署方案等维度,为轻量化视觉模型优化提供系统解决方案。

ZDQ58818的博客 272

POJ - 2019 Cornfields 【二维线段树】

题目链接:https://vjudge.net/problem/POJ-2019 我写的这个二维线段树没什么技巧,就是直接开一个 node[cur][cure],cur代表的是x轴的一维线段树,cure代表的是y轴的一维线段树。 初始化: 先从x轴开始做线段树的操作,当x轴到达叶节点时,再对y轴做线段树的操作,x轴返回到父节点时,一样要对y轴从1到N重头做一次线段树的操作,这是初始化的过程,...

Y390d的博客 247

4. SAP ABAP OData 服务 Data Provider Class 的 GET_ENTITYSET 方法实现指南

首先第19行CREATEDATA创建er_entityset实例,指定其类型为zcl_zbook_manage_mpc=>tt_book,接着把这个引用映射到刚刚第五行定义的FIELD-SYMBOLS变量上去,这样的话,接下来我们对FIELD-SYMBOLS进行的操作,就会自动反应回引用变量er_entityset.因为我们可能在这个方法里,返回多条图书信息,所以需要用内表类型,而非单条记录的ts_book.ts_book代表一本图书的数据结构。......

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2961

RMQ(一维+二维)附例题 POJ 3264,POJ 2019

代码功能 众所周之,求区间最值对于ACMer来说,是必须掌握的,为此我将之贴一下,注解也比较详细,方便查阅。 这段代码能够求一段连续的数在任意区间的最值。 代码区(一维+详细说明) #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #inclu...

天际苍穹的博客 291

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Poj 2019 Cornfields【二维RMQ-------ST算法】

Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6608   Accepted: 3234 Description FJ has decided to grow his own corn hybrid in order to help th

mengxiang000000 2015

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

【POJ 2019]二维RMQ

1.题目链接。题目大意,给定一个矩阵,k组询问,每组询问(x,y)输出以(x,y)为左上角,宽度为B的子矩阵里面最大值和最小值之差。 2.二维RMQ的裸题了,dp[i][j][a][b]代表的是当前点在(i,j)到(i+pow(2,a),j+pow(2,b))的最值。询问也是一样。模板题。 #include<iostream> #include <string.h> ...

YG爱木木 252

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

POJ - 2019 Cornfields 二维RMQ

题意 给出n∗n的矩阵。给出n∗n的矩阵。给出n*n的矩阵。 多次查询(x,y)为左上顶点,长度为b的子矩阵的最大值最小值差。多次查询(x,y)为左上顶点,长度为b的子矩阵的最大值最小值差。多次查询(x,y)为左上顶点,长度为b的子矩阵的最大值最小值差。 题解 二维ST表二维ST表二维ST表 给出两种二维RMQ写法给出两种二维RMQ写法给出两种二维RMQ写法 Code1Code...

Uniontake 503

poj 2019(二维RMQ)

Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3842   Accepted: 1823 Description FJ

志当存高远 1158

POJ2019 Cornfields 二维RMQ问题

二维RMQ问题 题意是输入

AC_Gibson的专栏 638

M - POJ 2019 二维RMQ

FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the cornfield on the flattest piece of land he can find. FJ has, a...

qq_42569807的博客 278

POJ 2019 二维RMQ

题意很明显。。 二维RMQ或者二维线段树 1.二维RMQ #include #include #include #include #include using namespace std; int val[255][255]; int dpmin[255][255][8][8];//最小值 int dpmax[255][255][8][8];//最大值 void init

' 泪 添 无 言's blog 395

poj 2019 Cornfields(二维RMQ)

Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5310   Accepted: 2613 Description FJ has decided to grow his own corn hybrid in order to help the co

WEYuLi的专栏 775

POJ - 2019(RMQ二维)

FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the cornfield on the flattest piece of land he can find.  FJ has, a...

bjfu170203101的博客 465

POJ 2019 Cornfields [二维RMQ]

二维RMQ。求一个矩阵的子矩阵各元素的最大值与最小值之差。用int会超内存,改用short。 #include #include #include #include #include using namespace std; const int maxn = 255; int n, b, k; short dpmin[maxn][maxn][10][10]; short dpm

~飞呀,飞~ 1221

POJ--2019--Cornfields【二维RMQ】

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define PI acos(-1.0) #def

阳光照耀圣西罗 740

POJ 2019 Cornfields 二维RMQ

题目来源:POJ 2019 Cornfields 题意:求正方形二维区间最大最小值的差 思路:直接二维ST搞 试模版而已 #include #include #include using namespace std; const int maxn = 255; int dp[maxn][maxn][8][8]; int dp2[maxn][maxn][8][8]; int a[

嗯。 1104
上一篇: hdu3966 点权模板-树链部分
下一篇: poj3237 树链部分 边权模板
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值