CF1783E.Game of the Year
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Monocarp and Polycarp are playing a computer game. This game features n bosses for the playing to kill, numbered from 1 to n .
They will fight each boss the following way:
- Monocarp makes k attempts to kill the boss;
- Polycarp makes k attempts to kill the boss;
- Monocarp makes k attempts to kill the boss;
- Polycarp makes k attempts to kill the boss;
- ...
Monocarp kills the i -th boss on his ai -th attempt. Polycarp kills the i -th boss on his bi -th attempt. After one of them kills the i -th boss, they move on to the (i+1) -st boss. The attempt counters reset for both of them. Once one of them kills the n -th boss, the game ends.
Find all values of k from 1 to n such that Monocarp kills all bosses.
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of testcases.
The first line of each testcase contains a single integer n ( 1≤n≤2⋅105 ) — the number of bosses.
The second line contains n integers a1,a2,…,an ( 1≤ai≤n ) — the index of attempt Monocarp kills each boss on.
The third line contains n integers b1,b2,…,bn ( 1≤bi≤n ) — the index of attempt Polycarp kills each boss on.
The sum of n over all testcases doesn't exceed 2⋅105 .
输出格式
For each testcase, print two lines. The first line should contain a single integer cnt — the number of values of k from 1 to n such that Monocarp kills all bosses. The second line should contain cnt distinct integers — the values of k themselves.
输入输出样例
输入#1
3 3 1 1 1 2 3 1 1 1 1 4 1 4 3 2 3 3 4 1
输出#1
3 1 2 3 1 1 2 2 4
说明/提示
Consider the last testcase of the example.
Let k=1 . First, Monocarp makes one attempt to kill the first boss. It's successful, since a1=1 . Then, Monocarp makes one attempt to kill the second boss. It's unsuccessful, since a2>1 . So, Polycarp makes an attempt then. It's also unsuccessful, since b2>1 . Then, Monocarp makes another attempt. It's still unsuccessful, since a2>2 . This goes on until Polycarp finally kills the boss on his third attempt. Monocarp didn't kill this boss, thus, k=1 isn't the answer.
Let k=2 . Monocarp still kills the first boss on his first attempt. Then, he makes two unsuccessful attempts for the second boss. Then, Polycarp makes two unsuccessful attempts. Then, Monocarp makes two more attempts and kills the boss on his fourth attempt. The third boss is similar. First, two unsuccessful attempts by Monocarp. Then, two unsuccessful attempts by Polycarp. Then, Monocarp has two more attempts, but even his first one is successful, since a3=3 . The fourth boss is also killed by Monocarp. Thus, k=2 is the answer.