CF2264E2.A Prime Flood (Hard Version)
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the Hard version of the problem. The difference between the versions is that in this version, n≤3⋅105. You can hack only if you solved all versions of this problem.
Antigun and Lamus have flooded Madamant's house. She wants them to make the water levels equal while removing as little water as possible.
Formally, the initial water levels are given by an array a=[a1,a2,…,an]. For each hypothetical cleanup, Antigun and Lamus select a non-empty subsequence∗ b of a. They may perform the following operation on b any number of times, possibly zero:
- choose a prime number p;
- simultaneously decrease every element bi whose current value is divisible by p by 1. All other elements remain unchanged.
Let f(b) be the maximum integer x such that, after some sequence of operations, every element of b is equal to x.
Find the sum of f(b) over all non-empty subsequences b of a, modulo 998244353. Subsequences formed by different choices of indices are counted separately, even if their values are equal.
Each subsequence is considered independently, starting from its original values.
∗A sequence a is a subsequence of a sequence b if a can be obtained from b by the deletion of several (possibly, zero or all) elements from arbitrary positions.
这是本题的困难版本。两个版本的区别在于,在本版本中,n≤3⋅105。仅当您已解决本题所有版本时,才可进行 Hack。
Antigun 和 Lamus 淹没了 Madamant 的房子。她希望他们使各处水位相等,同时尽可能少地移除水量。
形式化地,初始水位由数组 a=[a1,a2,…,an] 给出。对于每一种假设的清理方案,Antigun 和 Lamus 从 a 中选出一个非空子序列∗ b。他们可在 b 上执行如下操作任意多次(包括零次):
- 选择一个质数 p;
- 同时将 b 中所有当前值能被 p 整除的元素 bi 减少 1;其余元素保持不变。
令 f(b) 表示满足如下条件的最大整数 x:经过若干次操作后,b 的每个元素均等于 x。
求 a 的所有非空子序列 b 对应的 f(b) 之和,对 998244353 取模。即使不同下标选取的子序列具有相同元素值,也视为不同的子序列并分别计数。
每个子序列均独立考虑,且均从其原始值开始处理。
∗ 序列 a 是序列 b 的子序列,当且仅当 a 可通过从 b 的任意位置删除若干个(可能为零个或全部)元素而得到。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤300000) — the length of the array a.
The second line contains n integers a1,a2,…,an (1≤ai≤n) — the elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 300000.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤300000)—— 数组 a 的长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)—— 数组 a 的元素。
保证所有测试用例中 n 的总和不超过 300000。
输出格式
For each test case, print one integer — the sum of f(b) over all non-empty subsequences b of a, modulo 998244353.
对于每个测试用例,输出一个整数——即对数组 a 的所有非空子序列 b,求 f(b) 的和,并对 998244353 取模。
输入输出样例
输入#1
4 1 1 4 2 4 4 4 4 2 3 4 4 6 3 6 1 1 1 1
输出#1
1 37 34 72
说明/提示
In the first test case, the only non-empty subsequence is [1], and no operation is needed. Therefore, its contribution is f([1])=1.
In the second test case, the 23−1=7 non-empty subsequences containing only occurrences of 4 contribute 4⋅7=28. The subsequence [2] contributes 2. Each of the 7 subsequences containing the value 2 and at least one occurrence of 4 has f(b)=1. Hence, the answer is 28+2+7=37.
在第一个测试用例中,唯一的非空子序列为 [1],且无需进行任何操作。因此,其贡献值为 f([1])=1。
在第二个测试用例中,所有仅包含数字 4 的出现的 23−1=7 个非空子序列,其贡献值为 4⋅7=28;子序列 [2] 的贡献值为 2;每个包含数字 2 和至少一个 4 的子序列均有 f(b)=1,这样的子序列共 7 个。因此,答案为 28+2+7=37。
输入解题思路,AI测评打分。不知道怎么写?