GUPTA MECHANICAL

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

Saturday 25 June 2022

[Solution] Fishingprince Plays With Array Codeforces Solution


C. Fishingprince Plays With Array
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Fishingprince is playing with an array [a1,a2,,an]. He also has a magic number m.

He can do the following two operations on it:

  • Select 1in such that ai is divisible by m (that is, there exists an integer t such that mt=ai). Replace ai with m copies of aim. The order of the other elements doesn't change. For example, when m=2 and a=[2,3] and i=1a changes into [1,1,3].
  • Select 1inm+1 such that ai=ai+1==ai+m1. Replace these m elements with a single mai. The order of the other elements doesn't change. For example, when m=2 and a=[3,2,2,3] and i=2a changes into [3,4,3].


Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

Note that the array length might change during the process. The value of n above is defined as the current length of the array (might differ from the n in the input).

Fishingprince has another array [b1,b2,,bk]. Please determine if he can turn a into b using any number (possibly zero) of operations.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t104). Description of the test cases follows.


The first line of each test case contains two integers n and m (1n51042m109).

The second line of each test case contains n integers a1,a2,,an (1ai109).

The third line of each test case contains one integer k (1k5104).

The fourth line of each test case contains k integers b1,b2,,bk (1bi109).

It is guaranteed that the sum of n+k over all test cases does not exceed 2105.

Output

For each testcase, print Yes if it is possible to turn a into b, and No otherwise. You can print each letter in any case (upper or lower).

No comments:

Post a Comment