当前位置:网站首页>Educational Codeforces Round 132 (Rated for Div. 2) D. Rorororobot
Educational Codeforces Round 132 (Rated for Div. 2) D. Rorororobot
2022-07-23 09:40:00 【Vegetable newbie】
D. Rorororobot
题意
有一个n行m列的网格,每一列上 1 1 1~ a i a_i ai的位置上是障碍物,机器人可以连续走k步,给你一个起点和终点,问你能否在不路过障碍物和不超过格子的情况下从起点走到终点。
考点
数据结构,分类讨论
思路
首先,我们需要用数据结构维护出从起点列到终点列的最大值,我们设它为 x x x。
其次我们分情况讨论:
1.假如起和终点在同一列上,则只需要判断横坐标之差是不是k的倍数即可。
2.如果不在同一列,要保证两点横坐标的差和纵坐标的差的绝对值都是k的倍数
3.如果横坐标较大的那个点的高度比 x x x低,要保证能走到x上面但不越界的空白区域(如下图的棕色区域),在此区域走到另一个点的纵坐标那。
代码
const int N = 200010;
struct Node{
int maxn;
}seg[N * 4];
int a[N];
int n, m;
void pushup(int u){
seg[u].maxn = max(seg[u << 1].maxn, seg[u << 1 | 1].maxn);
}
void build(int u, int l, int r){
if(l == r){
seg[u].maxn = a[l];
return;
}
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
int query(int u, int l, int r, int ql, int qr){
if(l == ql && r == qr) return seg[u].maxn;
int mid = l + r >> 1;
if(qr <= mid) return query(u << 1, l, mid, ql, qr);
else if(ql > mid) return query(u << 1 | 1, mid + 1, r, ql, qr);
else return max(query(u << 1, l, mid, ql, mid), query(u << 1 | 1,mid + 1, r, mid + 1, qr));
}
int main(){
scanf("%d %d",&n, &m);
for(int i = 1; i <= m; i ++ ){
scanf("%d",&a[i]);
}
int q;
scanf("%d",&q);
build(1, 1, m);
while(q -- ){
int sx, sy, ex, ey, k;
scanf("%d %d %d %d %d",&sx, &sy, &ex, &ey, &k);
int miny = min(ey, sy), maxy = max(ey, sy);
int minx = min(ex, sx), maxx = max(ex, sx);
int a = abs(ex - sx), b = abs(ey - sy), x = query(1, 1, m, miny, maxy);
//在同一列
if(!b){
if(a % k) puts("No");
else puts("Yes");
continue;
}
if(a % k || b % k){
puts("No");
continue;
}
if(x < maxx){
puts("Yes");
continue;
}
int mod = (x - maxx) % k;
if(n - x + mod >= k) puts("Yes");
else puts("No");
}
return 0;
}
边栏推荐
- AI acceleration gesture recognition experience based on efr32mg24
- 【无标题】测试【无标题】测试
- mysql 之general_log日志
- 如何实现多个传感器与西门子PLC之间485无线通讯?
- Building personal network disk based on nextcloud
- Zhongwang CAD professional 2022 software installation package download and installation tutorial
- 头部姿态估计原理及可视化_loveliuzz的博客-程序员宅基地_头部姿态估计
- [paper notes] mobile robot navigation method based on hierarchical depth reinforcement learning
- @Feignclient detailed tutorial (illustration)
- 精品国创《少年歌行》数字藏品开售,邀你共铸少年武侠江湖梦
猜你喜欢

Wacom firmware update error 123, digital board driver cannot be updated

Building personal network disk based on nextcloud

运维高级作业03

Authing supports Zadig! Unified authentication and rapid docking of cloud native users

微信官方出品!小程序自动化框架 minium 分享预告

Dynamic programming -- knapsack problem

利用shell脚本实现封禁扫描频率过高的ip
![[test platform development] 20. Complete the function of sending interface request on the edit page](/img/ab/fed56b5bec990a25303c327733a8e6.png)
[test platform development] 20. Complete the function of sending interface request on the edit page

Work notes: one time bag grabbing

@FeignClient使用详细教程(图解)
随机推荐
[untitled]
Advanced operation and maintenance 03
About flex layout justify content: the last solution to the misalignment of space around and why it is solved like this is a discussion
It is suggested that Siyuan notes can be compatible with third-party sync disks
[software testing] how to sort out your testing business
LeetCode-227-基本计算器||
[C language] number guessing game + shutdown applet
Oracle 报表常用sql
Generate order number
CSDN写文方法(二)
【软件测试】盘一盘工作中遇到的 MQ 异常测试
Jetpack系列之Room中存Map结构
深度学习单图三维人脸重建
Yunna - how to strengthen fixed asset management? How to strengthen the management of fixed assets?
NVIDIA vid2vid论文复现
CAN总线快速了解
【小程序自动化Minium】一、框架介绍和环境搭建
【面试高频】cookie、session、token?看完再也不担心被问了
APtos 简介及机制
Yunna | how to manage fixed assets? How to manage fixed assets?