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 nn. Initially, the robot is at state aa. She wishes to turn it into state bb.

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 bb and paste it into the same place of the robot, replacing the original state there. However, she has to ensure that the sum of aa does not change after each copy operation in case the robot go haywire. Formally, Sanae can choose segment [l,r][l,r] and assign ai=bia_i = b_i (l≤i≤rl\le i\le r) if ∑i=1nai\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 aa to the desired state bb with any (possibly, zero) operations.

真的假的?!那个只存在于我想象中的机器人?!那个巨型步行机器人?!!

——古明地觉

小町制作了一个巨型机器人——飞天大圣,但它出了点问题。更糟的是,小町无法让它停下来,只能在现场紧急修复。

机器人的状态可以用一个长度为 nn 的整数数组表示。初始时,机器人处于状态 aa,而小町希望将其转变为状态 bb。

作为一名优秀的程序员,小町精通“复制-粘贴”技术。在一次操作中,她可以从给定的若干区间中选择一个区间,将 bb 中对应区间的值复制并粘贴到机器人当前状态 aa 的相同位置上,从而覆盖该位置原有的状态值。然而,她必须确保每次复制操作后,aa 数组的元素总和保持不变,以防机器人失控。形式化地说,小町可以选择区间 [l,r][l,r],并将所有 aia_i(其中 l≤i≤rl\le i\le r)赋值为 bib_i,但前提是操作前后 ∑i=1nai\sum\limits_{i=1}^n a_i 的值不发生变化。

请判断:小町是否能通过任意次(包括零次)这样的操作,成功将机器人从初始状态 aa 转变为目标状态 bb?

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤2⋅1041 \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 nn, mm (2≤n≤2⋅1052 \leq n\leq 2\cdot 10^5, 1≤m≤2⋅1051 \leq m\leq 2\cdot 10^5) — the length of aa, bb and the number of segments.

The second line contains nn intergers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤1091 \leq a_i \leq 10^9) — the initial state aa.

The third line contains nn intergers b1,b2,…,bnb_1,b_2,\ldots,b_n (1≤bi≤1091 \leq b_i \leq 10^9) — the desired state bb.

Then mm lines follow, the ii-th line contains two intergers li,ril_i,r_i (1≤li<ri≤n1 \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 nn and the sum of mm over all test cases does not exceed 2⋅1052 \cdot 10 ^ 5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤2⋅1041 \leq t \leq 2\cdot 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn、mm(2≤n≤2⋅1052 \leq n \leq 2\cdot 10^5,1≤m≤2⋅1051 \leq m \leq 2\cdot 10^5),分别表示数组 aa、bb 的长度以及可复制粘贴的区间段数量。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤1091 \leq a_i \leq 10^9),表示初始状态 aa。

第三行包含 nn 个整数 b1,b2,…,bnb_1,b_2,\ldots,b_n(1≤bi≤1091 \leq b_i \leq 10^9),表示目标状态 bb。

接下来是 mm 行,其中第 ii 行包含两个整数 li,ril_i,r_i(1≤li<ri≤n1 \leq l_i \lt r_i \leq n),表示由早苗可进行复制粘贴操作的区间段。

保证所有测试用例中 nn 的总和与 mm 的总和均不超过 2⋅1052 \cdot 10 ^ 5。

输出格式

For each test case, print "YES" (without quotes) if aa can be turned into bb, 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).

对于每个测试用例,如果 aa 可以被转换为 bb,则输出 "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 aa to bb:

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

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

Test case 2:

It can be shown that it is impossible to turn aa into bb.

测试用例 1:

将 aa 变为 bb 的一种可能方式如下:

首先,选择区间 [1,3][1,3]。操作后,a=[3,2,5,2,3]a=[3,2,5,2,3]。

然后,选择区间 [2,5][2,5]。操作后,a=[3,2,5,4,1]=ba=[3,2,5,4,1]=b。

测试用例 2:

可以证明,无法将 aa 变为 bb。

输入解题思路,AI测评打分。不知道怎么写?

首页