#P9714. 「QFOI R1」摸摸

    ID: 10924 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学洛谷原创Special JudgeO2优化构造洛谷月赛

「QFOI R1」摸摸

Problem Description

Little R is a lovely girl, and she likes having her head patted.

However, before patting her head, you must answer a question she asks.

She has an array aa of length nn, where all elements are initially 00. There are also two arrays t,bt, b of length nn.

She can perform two kinds of operations:

  1. Add tt to the reversed tt element by element, obtaining a new tt.
    • For example, t=[1,4,2]t=[1,4,2] becomes t=[1+2,4+4,2+1]=[3,8,3]t'=[1+2,4+4,2+1]=[3,8,3].
  2. Add aa to tt element by element, obtaining a new aa.
    • For example, a=[1,2,3],t=[1,4,2]a=[1,2,3],t=[1,4,2] becomes a=[1+1,2+4,3+2]=[2,6,5]a'=[1+1,2+4,3+2]=[2,6,5].

Is it possible to turn aa into bb by performing the operations above some number of times?

You want to pat her head TT times, so there are TT test cases.

Input Format

The first line contains an integer TT, meaning the number of test cases.

For each test case:

  • The first line contains an integer nn, meaning the array length.
  • The second line contains nn integers, where the ii-th integer is tit_i.
  • The third line contains nn integers, where the ii-th integer is bib_i.

Output Format

Output TT lines. Each line contains a string Yes or No, indicating whether it is possible to turn aa into bb for that test case.

The string is case-insensitive. If the answer is Yes, then yes, YES, yEs, etc. will all be accepted.

2
3
1 2 2
5 8 7
3
1 2 2
2 4 3
Yes
No

Hint

Sample Explanation

For the first test case:

  • Initially: a=[0,0,0]a=[0,0,0], t=[1,2,2]t=[1,2,2], b=[5,8,7]b=[5,8,7].
  • Perform operation 2: a=[1,2,2]a=[1,2,2], t=[1,2,2]t=[1,2,2], b=[5,8,7]b=[5,8,7].
  • Perform operation 2: a=[2,4,4]a=[2,4,4], t=[1,2,2]t=[1,2,2], b=[5,8,7]b=[5,8,7].
  • Perform operation 1: a=[2,4,4]a=[2,4,4], t=[3,4,3]t=[3,4,3], b=[5,8,7]b=[5,8,7].
  • Perform operation 2: a=[5,8,7]a=[5,8,7], t=[3,4,3]t=[3,4,3], b=[5,8,7]b=[5,8,7].

Now a=ba=b, which satisfies the requirement.

For the second test case, it can be proven that no valid solution exists.


Constraints

There are 2020 test points in total, with 55 points for each test point.

Let n\sum n denote the sum of nn over all test cases.

For all testdata, it is guaranteed that 1n2×1031\le \sum n\le 2\times 10^3, n1n\ge 1, 1ti,bi2×1031\le t_i,b_i\le 2\times 10^3.

  • For test points 141\sim 4: it is guaranteed that n2n\le 2.
  • For test points 585\sim 8: it is guaranteed that all tit_i are equal.
  • For test points 9129\sim 12: it is guaranteed that bi=bni+1b_i=b_{n-i+1}.
  • For test points 131613\sim 16: it is guaranteed that n,ti,bi200\sum n,t_i,b_i\le 200.
  • For test points 172017\sim 20: no special constraints.

Hack Data

Hack data was added after the contest, numbered starting from 2121.

The original test points are still worth 55 points each, and the Hack data is worth 00 points. However, you will be judged as Accepted only if you pass all data.

To distinguish the original test points from the Hack data, subtasks were added to this problem, but the scoring method of the subtasks is “sum”, which will not affect normal judging.

Translated by ChatGPT 5