A15180 | Rorororobot
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There is a grid, consisting of $n$ rows and $m$ columns. The rows are numbered from $1$ to $n$ from bottom to top. The columns are numbered from $1$ to $m$ from left to right. The $i$ -th column has the bottom $a_i$ cells blocked (the cells in rows $1, 2, \dots, a_i$ ), the remaining $n - a_i$ cells are unblocked.
A robot is travelling across this grid. You can send it commands — move up, right, down or left. If a robot attempts to move into a blocked cell or outside the grid, it explodes.
However, the robot is broken — it executes each received command $k$ times. So if you tell it to move up, for example, it will move up $k$ times ( $k$ cells). You can't send it commands while the robot executes the current one.
You are asked $q$ queries about the robot. Each query has a start cell, a finish cell and a value $k$ . Can you send the robot an arbitrary number of commands (possibly, zero) so that it reaches the finish cell from the start cell, given that it executes each command $k$ times?
The robot must stop in the finish cell. If it visits the finish cell while still executing commands, it doesn't count.
A robot is travelling across this grid. You can send it commands — move up, right, down or left. If a robot attempts to move into a blocked cell or outside the grid, it explodes.
However, the robot is broken — it executes each received command $k$ times. So if you tell it to move up, for example, it will move up $k$ times ( $k$ cells). You can't send it commands while the robot executes the current one.
You are asked $q$ queries about the robot. Each query has a start cell, a finish cell and a value $k$ . Can you send the robot an arbitrary number of commands (possibly, zero) so that it reaches the finish cell from the start cell, given that it executes each command $k$ times?
The robot must stop in the finish cell. If it visits the finish cell while still executing commands, it doesn't count.
输入格式
The first line contains two integers $n$ and $m$ ( $1 \le n \le 10^9$ ; $1 \le m \le 2 \cdot 10^5$ ) — the number of rows and columns of the grid.
The second line contains $m$ integers $a_1, a_2, \dots, a_m$ ( $0 \le a_i \le n$ ) — the number of blocked cells on the bottom of the $i$ -th column.
The third line contains a single integer $q$ ( $1 \le q \le 2 \cdot 10^5$ ) — the number of queries.
Each of the next $q$ lines contain five integers $x_s, y_s, x_f, y_f$ and $k$ ( $a[y_s] < x_s \le n$ ; $1 \le y_s \le m$ ; $a[y_f] < x_f \le n$ ; $1 \le y_f \le m$ ; $1 \le k \le 10^9$ ) — the row and the column of the start cell, the row and the column of the finish cell and the number of times each your command is executed. The start and the finish cell of each query are unblocked.
The second line contains $m$ integers $a_1, a_2, \dots, a_m$ ( $0 \le a_i \le n$ ) — the number of blocked cells on the bottom of the $i$ -th column.
The third line contains a single integer $q$ ( $1 \le q \le 2 \cdot 10^5$ ) — the number of queries.
Each of the next $q$ lines contain five integers $x_s, y_s, x_f, y_f$ and $k$ ( $a[y_s] < x_s \le n$ ; $1 \le y_s \le m$ ; $a[y_f] < x_f \le n$ ; $1 \le y_f \le m$ ; $1 \le k \le 10^9$ ) — the row and the column of the start cell, the row and the column of the finish cell and the number of times each your command is executed. The start and the finish cell of each query are unblocked.
输出格式
For each query, print "YES" if you can send the robot an arbitrary number of commands (possibly, zero) so that it reaches the finish cell from the start cell, given that it executes each command $k$ times. Otherwise, print "NO".
输入输出样例
输入 #1
11 10 9 0 0 10 3 4 8 11 10 8 6 1 2 1 3 1 1 2 1 3 2 4 3 4 5 2 5 3 11 5 3 5 3 11 5 2 11 9 9 10 1
输出 #1
YES NO NO NO YES YES
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted