## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Rorororobot Codeforces Solution 2022 | Solution Codeforces

D. Rorororobot
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Solution Click Below:-  👉
👇👇👇👇👇

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?

Input

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.

Three Doors Codeforces Solution 2022

Also Try Minecraft Codeforces Solution

Recover an RBS Codeforces Solution

Rorororobot Codeforces Solution

XOR Tree Codeforces Solution

Multiset of Strings Codeforces Solution

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\left[{y}_{s}\right]<{x}_{s}\le n$$1\le {y}_{s}\le m$$a\left[{y}_{f}\right]<{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.

Output

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".