Pathfinding is a task of finding a route between two points. It often appears in many problems. For example, in a GPS navigation software where a driver can query for a suggested route, or in a robot motion planning where it should find a valid sequence of movements to do some tasks, or in a simple maze solver where it should find a valid path from one point to another point. This problem is related to solving a maze.

The maze considered in this problem is in the form of a matrix of integers AA of N×NN×N. The value of each cell is generated from a given array RR and CC of NN integers each. Specifically, the value on the ithith row and jthjth column, cell (i,j)(i,j), is equal to Ri+CjRi+Cj. Note that all indexes in this problem are from 11 to NN.

A path in this maze is defined as a sequence of cells (r1,c1),(r2,c2),…,(rk,ck)(r1,c1),(r2,c2),…,(rk,ck) such that |ri−ri+1|+|ci−ci+1|=1|ri−ri+1|+|ci−ci+1|=1 for all 1≤i<k1≤i<k. In other words, each adjacent cell differs only by 11 row or only by 11 column. An even path in this maze is defined as a path in which all the cells in the path contain only even numbers.

Given a tuple ⟨ra,ca,rb,cb⟩⟨ra,ca,rb,cb⟩ as a query, your task is to determine whether there exists an even path from cell (ra,ca)(ra,ca) to cell (rb,cb)(rb,cb). To simplify the problem, it is guaranteed that both cell (ra,ca)(ra,ca) and cell (rb,cb)(rb,cb) contain even numbers.

For example, let N=5N=5, R={6,2,7,8,3}R={6,2,7,8,3}, and C={3,4,8,5,1}C={3,4,8,5,1}. The following figure depicts the matrix AA of 5×55×5 which is generated from the given array RR and CC.

Let us consider several queries:

⟨2,2,1,3⟩⟨2,2,1,3⟩: There is an even path from cell (2,2)(2,2) to cell (1,3)(1,3), e.g., (2,2),(2,3),(1,3)(2,2),(2,3),(1,3). Of course, (2,2),(1,2),(1,3)(2,2),(1,2),(1,3) is also a valid even path.
⟨4,2,4,3⟩⟨4,2,4,3⟩: There is an even path from cell (4,2)(4,2) to cell (4,3)(4,3), namely (4,2),(4,3)(4,2),(4,3).
⟨5,1,3,4⟩⟨5,1,3,4⟩: There is no even path from cell (5,1)(5,1) to cell (3,4)(3,4). Observe that the only two neighboring cells of (5,1)(5,1) are cell (5,2)(5,2) and cell (4,1)(4,1), and both of them contain odd numbers (7 and 11, respectively), thus, there cannot be any even path originating from cell (5,1)(5,1).
Input

Input begins with a line containing two integers: NN QQ (2≤N≤1000002≤N≤100000; 1≤Q≤1000001≤Q≤100000) representing the size of the maze and the number of queries, respectively. The next line contains NN integers: RiRi (0≤Ri≤1060≤Ri≤106) representing the array RR. The next line contains NN integers: CiCi (0≤Ci≤1060≤Ci≤106) representing the array CC. The next QQ lines each contains four integers: rara caca rbrb cbcb (1≤ra,ca,rb,cb≤N1≤ra,ca,rb,cb≤N) representing a query of ⟨ra,ca,rb,cb⟩⟨ra,ca,rb,cb⟩. It is guaranteed that (ra,ca)(ra,ca) and (rb,cb)(rb,cb) are two different cells in the maze and both of them contain even numbers.

Output

For each query in the same order as input, output in a line a string "YES" (without quotes) or "NO" (without quotes) whether there exists an even path from cell (ra,ca)(ra,ca) to cell (rb,cb)(rb,cb).

Examples

input

Copy

5 3
6 2 7 8 3
3 4 8 5 1
2 2 1 3
4 2 4 3
5 1 3 4
output

Copy

YES
YES
NO
input

Copy

3 2
30 40 49
15 20 25
2 2 3 3
1 2 2 2
output

Copy

NO
YES
Note

Explanation for the sample input/output #1

This is the example from the problem description.

解题思路:题目要求起点到终点的经过的每一个点的权值都为偶数,偶数的组合:奇+奇=偶、偶+偶=偶,利用数组row[]、col[],假设row[i]=x,表示从x开始到i的奇偶性相同,col[]同理,那实际上两个数组的值会组成一块区域,看终点是否存在这一个区域里面,需要保证的是起点的x、y都大于终点的x、y,如果起点的x、y都小于终点的x、y,那么起点可以说是终点,终点可以说是起点,如果起点只有x或y小于终点的x或y,相当于两个对称的点。

AC代码:

#include <iostream>
#include <cstdio>
#define N 100005 using namespace std; int R[N],C[N];
int col[N],row[N];
int main() {
int n, q;
cin >> n >> q;
for (int i = ; i <= n; i++)
scanf("%d", &R[i]);
for (int i = ; i <= n; i++)
scanf("%d", &C[i]);
row[] = col[] = ;
for (int i = ; i <= n; i++) {
if (R[i]% == R[i-]%)
row[i] = row[i - ];
else
row[i] = i;
if (C[i]% == C[i-]%)
col[i] = col[i - ];
else
col[i] = i;
}
while (q--) {
int ra, ca, rb, cb;
scanf("%d%d%d%d", &ra, &ca, &rb, &cb);
if(ra<rb)
swap(ra,rb);
if(ca<cb)
swap(ca,cb);
if (row[ra] <= rb && col[ca] <= cb)
puts("YES");
else
puts("NO");
}
return ;
}

2019-2020 ICPC, Asia Jakarta Regional Contest C. Even Path的更多相关文章

  1. 2019-2020 ICPC, Asia Jakarta Regional Contest C. Even Path(思维)

    Pathfinding is a task of finding a route between two points. It often appears in many problems. For ...

  2. 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)

    2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...

  3. 2019-2020 ICPC, Asia Jakarta Regional Contest H. Twin Buildings

    As you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC ...

  4. 2019-2020 ICPC, Asia Jakarta Regional Contest

    目录 Contest Info Solutions A. Copying Homework C. Even Path E. Songwriter G. Performance Review H. Tw ...

  5. 2018 ICPC Asia Jakarta Regional Contest

    题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . Ø Ø Ø Ø . Ο Ο:当场 Ø:已补 .  :  待补 A. Edit Distance Thin ...

  6. 2019-2020 ICPC, Asia Jakarta Regional Contest A. Copying Homework

    Danang and Darto are classmates. They are given homework to create a permutation of N integers from  ...

  7. 模拟赛小结:2019-2020 ICPC, Asia Jakarta Regional Contest

    比赛链接:传送门 离金最近的一次?,lh大佬carry场. Problem A. Copying Homework 00:17(+) Solved by Dancepted 签到,读题有点慢了.而且配 ...

  8. 2019-2020 ICPC, Asia Jakarta Regional Contest A. Copying Homework (思维)

    Danang and Darto are classmates. They are given homework to create a permutation of N integers from  ...

  9. Asia Jakarta Regional Contest 2019 I - Mission Possible

    cf的地址 因为校强, "咕咕十段"队获得了EC-final的参赛资格 因为我弱, "咕咕十段"队现在银面很大 于是咕咕十段决定进行训练. 周末vp了一场, 这 ...

随机推荐

  1. 粗暴,干就完了----徐晓冬似的C语言自学笔记---字符数组相关技术

    字符串拼接函数 strcat() 字符串----作为很多编程语言的鼻祖C语言,没有字符串类型,取而代之的字符数组,很多数组在声明的时候会给定数组长度,然而我们却可以这样写 char mywords[] ...

  2. 一个列表实现__iter__和__next__方法的例子

    x = ['厉智','陈培昌','程劲','徐晓冬'].__iter__() #这非得这么写不可,否则无法调用下面的__next__()方法,切记! print(x.__next__()) print ...

  3. 解决从其他地方拷贝过来的Android项目在本机不能运行(报错)的问题

    这个问题一般是由gradle版本不同引起的.要解决可以这样: 一.在确保本机Android studio 正常使用的情况下,在本机新建一个Android项目 二.在文件夹中打开新建的Android项目 ...

  4. vue_03总结

    vue_03总结 1.组件: html.css.js的集合体 vue实例就代表组件 组件用template实例成员管理html结构,有且只有一个根标签 子组件可以复用,所以数据要组件化处理,data的 ...

  5. 使用Future、asyncio处理并发

    并发的意义 为了高效处理网络I/O,需要使用并发,因为网络有很高的延迟,所以为了不浪费CPU周期去等待,最好在收到网络响应之前做些其他的事. 在I/O密集型应用中,如果代码写得正确,那么不管是用哪种并 ...

  6. joxj 模拟赛 2019年9月3日

    比赛题目来源:2018qbxt合肥Day1 T1 最小公倍数 题意:已知正整数n,求n与246913578的最小公倍数,结果对1234567890取模 数据范围:1<=n<=1010000 ...

  7. 剧终—AFO.

    /* noip一等完跪. 高考你好. 一年后山大见. AFO. */

  8. node中的koa2

    创建koa2工程 首先,我们创建一个目录hello-koa并作为工程目录用VS Code打开.然后,我们创建app.js,输入以下代码: // 导入koa,和koa 1.x不同,在koa2中,我们导入 ...

  9. ios端浏览器拍照上传到服务器,图片被旋转90度 php 解决方案

    1.可以通过前端进行解决,本案例通过后端解决的 判断请求的浏览器的ua,如果是ios浏览器则进行90度旋转 重点来了: 必须确保检测的图片是ios设备上传的完整图片,不要在前端压缩过的,因为压缩后的图 ...

  10. javascript操作表单

    表单元素除了可以运用上述所有DOM相关操作外,为了简化,还有一系列自己的属性和方法. 表单除了支持鼠标,键盘,更改和html时间之外,还支持一些表单特有的事件,如focus,change,blur等等 ...