当前位置:网站首页>Educational Codeforces Round 132 (Rated for Div. 2), problem: (D) Rorororobot
Educational Codeforces Round 132 (Rated for Div. 2), problem: (D) Rorororobot
2022-07-26 22:49:00 【ZaneBobo】
一个线段树板子题。
一.题意
有一个n*m的格子空间,现在你有一个机器人放在位置1,你想让他到达位置2,你每次可以向它发出向上向下向左向右四个指令,但是这个机器人他坏了,所以你每次发出指令后,他都会机械地执行你的指令k次,中途不可以暂停,这n*m的格子空间,每一列格子下面都有一定高度的格子是堵塞的,如果机器人走到堵塞的格子或者跑到墙壁外面的话,那这个机器人就会爆炸,问你能不能在机器人不爆炸的前提下给它发出指令让它从位置1走到位置2。
给到你行列,还有每列堵塞的格子有多高(因为从下往上堵),然后就是查询了,每个查询给你位置1和位置2还有每次机械执行的次数k。
二.思路
想要能够到达终止位置的话必定满足以下性质。
1.起始位置纵坐标与终止位置纵坐标之差的绝对值必须是k的整数。起始位置横坐标与终止位置横坐标之差的绝对值必须是k的整数。
2.必须能绕过他们之间最高的那列堵塞(利用线段树查询区间最大值的特性,找到哪个最大,然后二分机器人走几次k能第一次到达比最大堵塞高的位置,如果这个能到达的第一个比最大堵塞高的位置超出了墙壁,那就不行)
看到这里快要结束啦,很开心你可以点进来,如果文章对你有帮助的话,可以顺手点一下下面的小手手吗?你的支持是对我创作最大的鼓励 !
三.代码
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
#include<cstdio>
using namespace std;
const int N = 2e5+10;
typedef long long LL;
const int maxn=2e6+10;
int a[maxn],segMax[maxn*4];//线段树数组要开大4倍
void build(int cur,int L,int R)
{//cur表示区间[L,R]的标号
if(L==R) segMax[cur]=a[L];
else
{
int mid=(L+R)/2;
build(cur*2,L,mid);
build(cur*2+1,mid+1,R);
segMax[cur]=max(segMax[cur*2],segMax[cur*2+1]);
}
}
int get_max(int cur,int L,int R,int x,int y)
{ //查询区间[x,y]的最大值
if(x>R||y<L) return -0x3f3f3f3f; //求最大值,此时设置返回负无穷大
if(x<=L&&y>=R) return segMax[cur];
int mid=(L+R)/2;
return max(get_max(cur*2,L,mid,x,y),get_max(cur*2+1,mid+1,R,x,y));
}
void solve()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>a[i];
}
build(1,1,m);
int q;
cin>>q;
while(q--)
{
LL x1,y1,x2,y2;
LL k;
scanf("%lld%lld%lld%lld%lld",&x1,&y1,&x2,&y2,&k);
if(abs(x2-x1)%k!=0||abs(y2-y1)%k!=0)//性质1
{
puts("NO");
continue;
}
LL maxx=get_max(1,1,m,min(y1,y2),max(y1,y2));//线段树查询区间最大值
LL l=0,r=1e10;
while(l<r)
{
LL mid=(l+r)>>1;
if((LL)(mid*k+(LL)min(x1,x2))>maxx) r=mid;
else l=mid+1;
}
if(r*k+min(x1,x2)>n||r*k+min(x1,x2)<=maxx)//①超出墙壁②跳不过最高堵塞
{
puts("NO");
continue;
}
puts("YES");
}
}
int main()
{
int T;
T=1;
while(T--)
{
solve();
}
}边栏推荐
- C语言——数据类型、基本数据类型的取值范围
- 选择器的使用语法与场景以及背景图片大小、文字盒子阴影、过度效果的使用方法
- 机械硬盘选购指南——从选购经历谈起
- Dynamic routing ofps protocol configuration
- Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis
- ensp中的简单静态路由
- [详解C语言]一文带你玩转循环结构(for_while_do-while)
- HCIA(网络初级综合实验练习)
- Static comprehensive experiment (comprehensive exercise of static route, loopback interface, default route, empty interface, floating static)
- RIP V2 的简单应用(v2的配置、宣告、手工汇总、RIPV2的认证、沉默接口、加快收敛)
猜你喜欢

2022最新直播监控24小时监控(三)直播间弹幕解析

7.16 written examination of Duoyi network

NAT (network address translation protocol)

mgre的全连和星型拓扑实验

Text to image paper intensive reading ssa-gan: text to image generation with semantic spatial aware Gan

Nat网络地址转换实验
![[explain C language in detail] takes you to play with the choice (Branch) structure](/img/ca/7ee9f62a2478785c97684c7a0cc749.png)
[explain C language in detail] takes you to play with the choice (Branch) structure

二层封装技术(HDLC、PPP--PAP\CHAP、GRE)实验练习

TCP的三次握手与四次断开

Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis
随机推荐
MySQL课程1.简单命令行--简单记录 欢迎补充纠错
Gan's training skills: alchemist cultivation plan - generative confrontation network training, participation and improvement
HCIA Basics (1)
The gradient descent method and Newton method are used to calculate the open radical
RIP V2 的简单应用(v2的配置、宣告、手工汇总、RIPV2的认证、沉默接口、加快收敛)
解决方案:炼丹师养成计划 Pytorch+DeepLearning遇见的各种报错与踩坑避坑记录(一)
C语言——while语句、dowhile语句、for循环和循环结构、break语句和continue语句
STM32入门教程第二讲
动态路由rip协议实验
[FPGA tutorial case 28] one of DDS direct digital frequency synthesizers based on FPGA -- principle introduction
NAT (network address translation protocol)
OSPF static experiment
js求最大值?
2022 latest live broadcast monitoring 24-hour monitoring (III) analysis of barrage in live broadcast room
[FPGA tutorial case 29] the second DDS direct digital frequency synthesizer based on FPGA - Verilog development
[详解C语言]一文带你玩转循环结构(for_while_do-while)
6.28 Dahua written examination
Text to image论文精读DF-GAN:A Simple and Effective Baseline for Text-to-Image Synthesis一种简单有效的文本生成图像基准模型
Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (II)
2022zui新抖音24小时循环值守直播监控(一)直播间开播监控