Codeforces Round 796 (Div. 1)
C
Sanae and Giant Robot
Codeforces
2500
原题
← BD →
翻译中…

Is it really?! The robot only existing in my imagination?! The Colossal Walking Robot?!!— Kochiya Sanae

翻译中…

Sanae made a giant robot — Hisoutensoku, but something is wrong with it. To make matters worse, Sanae can not figure out how to stop it, and she is forced to fix it on-the-fly.

翻译中…

The state of a robot can be represented by an array of integers of length $n$. Initially, the robot is at state $a$. She wishes to turn it into state $b$.

翻译中…

As a great programmer, Sanae knows the art of copy-and-paste. In one operation, she can choose some segment from given segments, copy the segment from $b$ and paste it into the same place of the robot, replacing the original state there. However, she has to ensure that the sum of $a$ does not change after each copy operation in case the robot go haywire. Formally, Sanae can choose segment $[l,r]$ and assign $a_i = b_i$ ($l\le i\le r$) if $\sum\limits_{i=1}^n a_i$ does not change after the operation.

翻译中…

Determine whether it is possible for Sanae to successfully turn the robot from the initial state $a$ to the desired state $b$ with any (possibly, zero) operations.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 2\cdot 10^4$) — the number of test cases. The descriptions of the test cases follow.

翻译中…

The first line of each test case contains two integers $n$, $m$ ($2 \leq n\leq 2\cdot 10^5$, $1 \leq m\leq 2\cdot 10^5$) — the length of $a$, $b$ and the number of segments.

翻译中…

The second line contains $n$ intergers $a_1,a_2,\ldots,a_n$ ($1 \leq a_i \leq 10^9$) — the initial state $a$.

翻译中…

The third line contains $n$ intergers $b_1,b_2,\ldots,b_n$ ($1 \leq b_i \leq 10^9$) — the desired state $b$.

翻译中…

Then $m$ lines follow, the $i$-th line contains two intergers $l_i,r_i$ ($1 \leq l_i \lt r_i \leq n$) — the segments that can be copy-pasted by Sanae.

翻译中…

It is guaranteed that both the sum of $n$ and the sum of $m$ over all test cases does not exceed $2 \cdot 10 ^ 5$.

翻译中…

Output

翻译中…

For each test case, print "YES" (without quotes) if $a$ can be turned into $b$, or "NO" (without quotes) otherwise.

翻译中…

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

翻译中…

Note

翻译中…

Test case 1:

翻译中…

One possible way of turning $a$ to $b$:

翻译中…

First, select $[1,3]$. After the operation, $a=[3,2,5,2,3]$.

翻译中…

Then, select $[2,5]$. After the operation, $a=[3,2,5,4,1]=b$.

翻译中…

Test case 2:

翻译中…

It can be shown that it is impossible to turn $a$ into $b$.

翻译中…

样例

Input #1
2
5 2
1 5 4 2 3
3 2 5 4 1
1 3
2 5
5 2
1 5 4 2 3
3 2 4 5 1
1 2
2 4
Output #1
YES
NO
InputCopy OutputCopy
题目信息
题号
1687C
时间限制
1 s
内存限制
256 MB
标签
二分
暴力
数据结构
并查集
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。