CF2171G.Sakura Adachi and Optimal Sequences

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

"What a pain..."

— Hougetsu Shimamura

Adachi is in the middle of a generational crashout... over, uh, this problem! Yep, that's definitely it... anyways, please help her solve it!

You are given two arrays aa and bb of length nn (1≤ai≤bi1\leq a_i\leq b_i).

In one operation, you may either:

  • choose an index ii (1≤i≤n1\leq i\leq n) and set ai:=ai+1a_i := a_i + 1, or
  • double all elements of aa.

Let xx denote the minimum number of operations needed to make a=ba = b. Two arrays aa and bb of length nn are considered equal if ai=bia_i = b_i for all 1≤i≤n1\leq i\leq n.

Find the value of xx. Additionally, count the number of sequences of operations that make a=ba = b using exactly xx operations. Two such sequences of operations are considered different if, for any 1≤j≤x1\leq j\leq x, the jj-th operation of each sequence differs (either in the type of operation selected or the index chosen, if applicable).

Since the number of sequences may be large, output it modulo 106+3{\color{red}{10^6+3}}. Note that 106+310^6+3 is a prime number.

“真是麻烦啊……”

—— 望月志村

安达正陷入一代人的崩溃……原因嘛,呃,就是这道题!没错,肯定就是它了……总之,请帮她解决这个问题吧!

给你两个长度为 nn 的数组 aa 和 bb(满足 1≤ai≤bi1\leq a_i\leq b_i)。

每次操作你可以执行以下两种之一:

  • 选择一个下标 ii(1≤i≤n1\leq i\leq n),并将 aia_i 替换为 ai+1a_i + 1;或者
  • 将数组 aa 的所有元素翻倍(即对每个 ii,令 ai:=2⋅aia_i := 2 \cdot a_i)。

记 xx 为使 a=ba = b 所需的最少操作次数。当且仅当对所有 1≤i≤n1\leq i\leq n 均有 ai=bia_i = b_i 时,称两个长度为 nn 的数组 aa 和 bb 相等。

请计算 xx 的值。此外,还需统计恰好使用 xx 次操作使 a=ba = b 的操作序列的个数。若存在某个 1≤j≤x1\leq j\leq x,使得两个操作序列的第 jj 步操作不同(操作类型不同,或在同为第一类操作时所选下标 ii 不同),则认为这两个操作序列不同。

由于方案数可能很大,请将该数目对 106+3{\color{red}{10^6+3}} 取模后输出。注意:106+310^6+3 是一个质数。

输入格式

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

The first line of each test case contains a single integer nn (2≤n≤2⋅1052\leq n\leq 2\cdot 10^5).

The second line of each test case contains nn integers, a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1061\leq a_i\leq 10^6).

The third line of each test case contains nn integers, b1,b2,…,bnb_1, b_2, \dots, b_n (ai≤bi≤106a_i\leq b_i\leq 10^6).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052\leq n\leq 2\cdot 10^5)。

每个测试用例的第二行包含 nn 个整数:a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1061\leq a_i\leq 10^6)。

每个测试用例的第三行包含 nn 个整数:b1,b2,…,bnb_1, b_2, \dots, b_n(ai≤bi≤106a_i\leq b_i\leq 10^6)。

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

输出格式

For each test case, output two integers, the value of xx, and the number of sequences of operations that make a=ba = b using exactly xx operations, modulo 106+310^6+3. The value of xx should be printed exactly; that is, it should not be taken modulo 106+310^6 + 3.

对于每个测试用例,输出两个整数:xx 的值,以及恰好使用 xx 次操作使得 a=ba = b 的操作序列数量(对 106+310^6+3 取模)。xx 的值应原样输出;即,不应对其取模 106+310^6 + 3。

输入输出样例

  • 输入#1

    8
    6
    1 3 6 4 3 2
    3 7 10 4 4 8
    2
    1 1
    4 3
    5
    2 3 2 5 1
    18 13 10 30 7
    5
    5 4 3 6 2
    100 125 231 113 107
    4
    2 2 2 2
    2 2 2 2
    4
    1 1 1 1
    2 2 2 2
    7
    1 1 1 1 1 1 200000
    200000 200000 200000 200000 200000 200000 200000
    3
    542264 174876 441510
    641112 325241 995342

    输出#1

    17 827116
    3 1
    12 288
    35 567812
    0 1
    1 1
    1199994 0
    803045 366998

说明/提示

In the second sample, it is possible to convert aa into bb using only three operations. There is only one way to do so, namely:

  • Add 11 to a1a_1, yielding a=[2,1]a = [2, 1]. Then double all elements of aa, yielding a=[4,2]a = [4, 2]. Then add 11 to a2a_2, yielding a=[4,3]a = [4, 3]. Then we have that a=ba = b, as desired.

It can be shown that it is impossible to convert aa into bb using fewer than three operations.

在第二个样例中,仅需三次操作即可将 aa 转换为 bb。实现该转换的唯一方式如下:

  • 将 a1a_1 加 11,得到 a=[2,1]a = [2, 1];然后将 aa 的所有元素乘以 22,得到 a=[4,2]a = [4, 2];再将 a2a_2 加 11,得到 a=[4,3]a = [4, 3]。此时即有 a=ba = b,符合要求。

可以证明:无法用少于三次操作将 aa 转换为 bb。

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

首页