GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday, 3 June 2022

[Solution] Sanae and Giant Robot Codeforces Solution | Codeforces Problem Solution 2022

F. Sanae and Giant Robot
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 (lir) if i=1nai does not change after the operation.

Solution Click Below:-  CLICK HERE

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 (1t2104) — the number of test cases. The descriptions of the test cases follow.

The first line of each test case contains two integers nm (2n21051m2105) — the length of ab and the number of segments.

The second line contains n intergers a1,a2,,an (1ai109) — the initial state a.

The third line contains n intergers b1,b2,,bn (1bi109) — the desired state b.

Then m lines follow, the i-th line contains two intergers li,ri (1li<rin) — 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 2105.

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).


No comments:

Post a Comment