CF1687C.Sanae and Giant Robot
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ai=bi (l≤i≤r) if i=1∑nai 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.
真的假的?!那个只存在于我想象中的机器人?!那个巨型步行机器人?!!
——古明地觉
小町制作了一个巨型机器人——飞天大圣,但它出了点问题。更糟的是,小町无法让它停下来,只能在现场紧急修复。
机器人的状态可以用一个长度为 n 的整数数组表示。初始时,机器人处于状态 a,而小町希望将其转变为状态 b。
作为一名优秀的程序员,小町精通“复制-粘贴”技术。在一次操作中,她可以从给定的若干区间中选择一个区间,将 b 中对应区间的值复制并粘贴到机器人当前状态 a 的相同位置上,从而覆盖该位置原有的状态值。然而,她必须确保每次复制操作后,a 数组的元素总和保持不变,以防机器人失控。形式化地说,小町可以选择区间 [l,r],并将所有 ai(其中 l≤i≤r)赋值为 bi,但前提是操作前后 i=1∑nai 的值不发生变化。
请判断:小町是否能通过任意次(包括零次)这样的操作,成功将机器人从初始状态 a 转变为目标状态 b?
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤2⋅104) — 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≤n≤2⋅105, 1≤m≤2⋅105) — the length of a, b and the number of segments.
The second line contains n intergers a1,a2,…,an (1≤ai≤109) — the initial state a.
The third line contains n intergers b1,b2,…,bn (1≤bi≤109) — the desired state b.
Then m lines follow, the i-th line contains two intergers li,ri (1≤li<ri≤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⋅105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤2⋅104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n、m(2≤n≤2⋅105,1≤m≤2⋅105),分别表示数组 a、b 的长度以及可复制粘贴的区间段数量。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109),表示初始状态 a。
第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤109),表示目标状态 b。
接下来是 m 行,其中第 i 行包含两个整数 li,ri(1≤li<ri≤n),表示由早苗可进行复制粘贴操作的区间段。
保证所有测试用例中 n 的总和与 m 的总和均不超过 2⋅105。
输出格式
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).
对于每个测试用例,如果 a 可以被转换为 b,则输出 "YES"(不带引号),否则输出 "NO"(不带引号)。
您可以以任意大小写形式输出 "YES" 和 "NO"(例如,字符串 "yEs"、"yes" 和 "Yes" 均会被识别为肯定回答)。
输入输出样例
输入#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
输出#1
YES NO
说明/提示
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.
测试用例 1:
将 a 变为 b 的一种可能方式如下:
首先,选择区间 [1,3]。操作后,a=[3,2,5,2,3]。
然后,选择区间 [2,5]。操作后,a=[3,2,5,4,1]=b。
测试用例 2:
可以证明,无法将 a 变为 b。
输入解题思路,AI测评打分。不知道怎么写?