CF1687C.Sanae and Giant Robot

普及/提高-

通过率:0%

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 ( lirl\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.

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t21041 \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 ( 2n21052 \leq n\leq 2\cdot 10^5 , 1m21051 \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 ( 1ai1091 \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 ( 1bi1091 \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 ( 1li<rin1 \leq l_i < 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 21052 \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).

输入输出样例

  • 输入#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 .

首页