CF1709D.Rorororobot

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a grid, consisting of nn rows and mm columns. The rows are numbered from 11 to nn from bottom to top. The columns are numbered from 11 to mm from left to right. The ii -th column has the bottom aia_i cells blocked (the cells in rows 1,2,,ai1, 2, \dots, a_i ), the remaining nain - 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 kk times. So if you tell it to move up, for example, it will move up kk times ( kk cells). You can't send it commands while the robot executes the current one.

You are asked qq queries about the robot. Each query has a start cell, a finish cell and a value kk . 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 kk 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 nn and mm ( 1n1091 \le n \le 10^9 ; 1m21051 \le m \le 2 \cdot 10^5 ) — the number of rows and columns of the grid.

The second line contains mm integers a1,a2,,ama_1, a_2, \dots, a_m ( 0ain0 \le a_i \le n ) — the number of blocked cells on the bottom of the ii -th column.

The third line contains a single integer qq ( 1q21051 \le q \le 2 \cdot 10^5 ) — the number of queries.

Each of the next qq lines contain five integers xs,ys,xf,yfx_s, y_s, x_f, y_f and kk ( a[ys]<xsna[y_s] < x_s \le n ; 1ysm1 \le y_s \le m ; a[yf]<xfna[y_f] < x_f \le n ; 1yfm1 \le y_f \le m ; 1k1091 \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 kk 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
首页