CF1783E.Game of the Year

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Monocarp and Polycarp are playing a computer game. This game features nn bosses for the playing to kill, numbered from 11 to nn.

They will fight each boss the following way:

  • Monocarp makes kk attempts to kill the boss;
  • Polycarp makes kk attempts to kill the boss;
  • Monocarp makes kk attempts to kill the boss;
  • Polycarp makes kk attempts to kill the boss;
  • ...

Monocarp kills the ii-th boss on his aia_i-th attempt. Polycarp kills the ii-th boss on his bib_i-th attempt. After one of them kills the ii-th boss, they move on to the (i+1)(i+1)-st boss. The attempt counters reset for both of them. Once one of them kills the nn-th boss, the game ends.

Find all values of kk from 11 to nn such that Monocarp kills all bosses.

Monocarp 和 Polycarp 正在玩一款电脑游戏。该游戏包含 nn 个供玩家击杀的 Boss,编号从 11 到 nn。

他们按如下方式逐个挑战每个 Boss:

  • Monocarp 尝试击杀该 Boss 共 kk 次;
  • Polycarp 尝试击杀该 Boss 共 kk 次;
  • Monocarp 尝试击杀该 Boss 共 kk 次;
  • Polycarp 尝试击杀该 Boss 共 kk 次;
  • ……

Monocarp 在他针对第 ii 个 Boss 的第 aia_i 次尝试时成功击杀该 Boss;Polycarp 在他针对第 ii 个 Boss 的第 bib_i 次尝试时成功击杀该 Boss。一旦其中一人成功击杀第 ii 个 Boss,他们便立即转向第 (i+1)(i+1) 个 Boss,且两人各自的尝试计数器均重置为零。当其中一人成功击杀第 nn 个 Boss 时,游戏结束。

请找出所有满足 1≤k≤n1 \le k \le n 的整数 kk,使得 Monocarp 成功击杀全部 nn 个 Boss。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of testcases.

The first line of each testcase contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of bosses.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n) — the index of attempt Monocarp kills each boss on.

The third line contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (1≤bi≤n1 \le b_i \le n) — the index of attempt Polycarp kills each boss on.

The sum of nn over all testcases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— Boss 的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \le a_i \le n)—— Monocarp 击败每个 Boss 所在的尝试序号。

第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤bi≤n1 \le b_i \le n)—— Polycarp 击败每个 Boss 所在的尝试序号。

所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each testcase, print two lines. The first line should contain a single integer cnt\mathit{cnt} — the number of values of kk from 11 to nn such that Monocarp kills all bosses. The second line should contain cnt\mathit{cnt} distinct integers — the values of kk themselves.

对于每个测试用例,输出两行。第一行应包含一个整数 cnt\mathit{cnt} —— 表示在 11 到 nn 范围内满足 Monocarp 能击败所有 Boss 的 kk 的个数。第二行应包含 cnt\mathit{cnt} 个互不相同的整数 —— 即所有满足条件的 kk 值本身。

输入输出样例

  • 输入#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=1k = 1. First, Monocarp makes one attempt to kill the first boss. It's successful, since a1=1a_1 = 1. Then, Monocarp makes one attempt to kill the second boss. It's unsuccessful, since a2>1a_2 \gt 1. So, Polycarp makes an attempt then. It's also unsuccessful, since b2>1b_2 \gt 1. Then, Monocarp makes another attempt. It's still unsuccessful, since a2>2a_2 \gt 2. This goes on until Polycarp finally kills the boss on his third attempt. Monocarp didn't kill this boss, thus, k=1k = 1 isn't the answer.

Let k=2k = 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=3a_3 = 3. The fourth boss is also killed by Monocarp. Thus, k=2k = 2 is the answer.

考虑示例中的最后一个测试用例。

设 k=1k = 1。首先,Monocarp 尝试击杀第一个 Boss 一次。这次成功了,因为 a1=1a_1 = 1。接着,Monocarp 尝试击杀第二个 Boss 一次,但失败了,因为 a2>1a_2 \gt 1。于是 Polycarp 尝试一次,也失败了,因为 b2>1b_2 \gt 1。随后 Monocarp 再次尝试,仍失败,因为 a2>2a_2 \gt 2。如此继续,直到 Polycarp 在他的第三次尝试时终于击杀该 Boss。Monocarp 并未击杀这个 Boss,因此 k=1k = 1 不是答案。

设 k=2k = 2。Monocarp 依然在第一次尝试中就成功击杀第一个 Boss。接着,他对第二个 Boss 进行两次失败的尝试;然后 Polycarp 也进行两次失败的尝试;之后 Monocarp 再进行两次尝试,并在他第四次尝试时成功击杀该 Boss。第三个 Boss 的情况类似:Monocarp 先两次失败,Polycarp 再两次失败,随后 Monocarp 又获得两次尝试机会——但甚至第一次就成功了,因为 a3=3a_3 = 3。第四个 Boss 同样由 Monocarp 击杀。因此,k=2k = 2 是答案。

输入解题思路,AI测评打分。不知道怎么写?

首页