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 a and b of length n (1≤ai≤bi).
In one operation, you may either:
- choose an index i (1≤i≤n) and set ai:=ai+1, or
- double all elements of a.
Let x denote the minimum number of operations needed to make a=b. Two arrays a and b of length n are considered equal if ai=bi for all 1≤i≤n.
Find the value of x. Additionally, count the number of sequences of operations that make a=b using exactly x operations. Two such sequences of operations are considered different if, for any 1≤j≤x, the j-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. Note that 106+3 is a prime number.
“真是麻烦啊……”
—— 望月志村
安达正陷入一代人的崩溃……原因嘛,呃,就是这道题!没错,肯定就是它了……总之,请帮她解决这个问题吧!
给你两个长度为 n 的数组 a 和 b(满足 1≤ai≤bi)。
每次操作你可以执行以下两种之一:
- 选择一个下标 i(1≤i≤n),并将 ai 替换为 ai+1;或者
- 将数组 a 的所有元素翻倍(即对每个 i,令 ai:=2⋅ai)。
记 x 为使 a=b 所需的最少操作次数。当且仅当对所有 1≤i≤n 均有 ai=bi 时,称两个长度为 n 的数组 a 和 b 相等。
请计算 x 的值。此外,还需统计恰好使用 x 次操作使 a=b 的操作序列的个数。若存在某个 1≤j≤x,使得两个操作序列的第 j 步操作不同(操作类型不同,或在同为第一类操作时所选下标 i 不同),则认为这两个操作序列不同。
由于方案数可能很大,请将该数目对 106+3 取模后输出。注意:106+3 是一个质数。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n (2≤n≤2⋅105).
The second line of each test case contains n integers, a1,a2,…,an (1≤ai≤106).
The third line of each test case contains n integers, b1,b2,…,bn (ai≤bi≤106).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(2≤n≤2⋅105)。
每个测试用例的第二行包含 n 个整数:a1,a2,…,an(1≤ai≤106)。
每个测试用例的第三行包含 n 个整数:b1,b2,…,bn(ai≤bi≤106)。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output two integers, the value of x, and the number of sequences of operations that make a=b using exactly x operations, modulo 106+3. The value of x should be printed exactly; that is, it should not be taken modulo 106+3.
对于每个测试用例,输出两个整数:x 的值,以及恰好使用 x 次操作使得 a=b 的操作序列数量(对 106+3 取模)。x 的值应原样输出;即,不应对其取模 106+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 a into b using only three operations. There is only one way to do so, namely:
- Add 1 to a1, yielding a=[2,1]. Then double all elements of a, yielding a=[4,2]. Then add 1 to a2, yielding a=[4,3]. Then we have that a=b, as desired.
It can be shown that it is impossible to convert a into b using fewer than three operations.
在第二个样例中,仅需三次操作即可将 a 转换为 b。实现该转换的唯一方式如下:
- 将 a1 加 1,得到 a=[2,1];然后将 a 的所有元素乘以 2,得到 a=[4,2];再将 a2 加 1,得到 a=[4,3]。此时即有 a=b,符合要求。
可以证明:无法用少于三次操作将 a 转换为 b。
输入解题思路,AI测评打分。不知道怎么写?