CF1789E.Serval and Music Game
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Serval loves playing music games. He meets a problem when playing music games, and he leaves it for you to solve.
You are given n positive integers s1<s2<…<sn. f(x) is defined as the number of i (1≤i≤n) that exist non-negative integers pi,qi such that:
s_i=p_ileftlfloors_noverxrightrfloor+q_ileftlceils_noverxrightrceil
Find out ∑x=1snx⋅f(x) modulo 998244353.
As a reminder, ⌊x⌋ denotes the maximal integer that is no greater than x, and ⌈x⌉ denotes the minimal integer that is no less than x.
小猫塞尔瓦喜欢玩音乐游戏。他在玩音乐游戏时遇到了一个问题,现在交由你来解决。
给定 n 个正整数 s1<s2<…<sn。定义函数 f(x) 为满足如下条件的下标 i(其中 1≤i≤n)的个数:存在非负整数 pi,qi,使得
s_i=p_ileftlfloors_noverxrightrfloor+q_ileftlceils_noverxrightrceil
请计算 ∑x=1snx⋅f(x) 对 998244353 取模的结果。
提示:⌊x⌋ 表示不超过 x 的最大整数(即向下取整),⌈x⌉ 表示不小于 x 的最小整数(即向上取整)。
输入格式
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 cases contains a single integer n (1≤n≤106).
The second line of each test case contains n positive integers s1,s2,…,sn (1≤s1<s2<…<sn≤107).
It is guaranteed that the sum of n over all test cases does not exceed 106, and the sum of sn does not exceed 107.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤106)。
每个测试用例的第二行包含 n 个正整数 s1,s2,…,sn(1≤s1<s2<…<sn≤107)。
保证所有测试用例的 n 之和不超过 106,且所有测试用例的 sn 之和不超过 107。
输出格式
For each test case, print a single integer in a single line — the sum of x⋅f(x) over all possible x modulo 998244353.
对于每个测试用例,在一行中输出一个整数——对所有可能的 x,求 x⋅f(x) 的和,并对 998244353 取模。
输入输出样例
输入#1
4 3 1 2 4 4 1 2 7 9 4 344208 591000 4779956 5403429 5 1633 1661 1741 2134 2221
输出#1
26 158 758737625 12334970
说明/提示
For the first test case, sn=4, f(x) are calculated as followings:
- f(1)=1
- ⌊1sn⌋=4, ⌈1sn⌉=4.
- It can be shown that such p1,p2 and q1,q2 that satisfy the conditions don't exist.
- Let p3=1 and q3=0, then s3=p3⋅⌊1sn⌋+q3⋅⌈1sn⌉=1⋅4+0⋅4=4.
- f(2)=2
- ⌊2sn⌋=2, ⌈2sn⌉=2.
- It can be shown that such p1 and q1 that satisfy the conditions don't exist.
- Let p2=1 and q2=0, then s2=p2⋅⌊2sn⌋+q2⋅⌈2sn⌉=1⋅2+0⋅2=2.
- Let p3=0 and q3=2, then s3=p3⋅⌊2sn⌋+q3⋅⌈2sn⌉=0⋅2+2⋅2=4.
- f(3)=3
- ⌊3sn⌋=1, ⌈3sn⌉=2.
- Let p1=1 and q1=0, then s1=p1⋅⌊3sn⌋+q1⋅⌈3sn⌉=1⋅1+0⋅2=1.
- Let p2=0 and q2=1, then s2=p2⋅⌊3sn⌋+q2⋅⌈3sn⌉=0⋅1+1⋅2=2.
- Let p3=0 and q3=2, then s3=p3⋅⌊3sn⌋+q3⋅⌈3sn⌉=0⋅1+2⋅2=4.
- f(4)=3
- ⌊4sn⌋=1, ⌈4sn⌉=1.
- Let p1=1 and q1=0, then s1=p1⋅⌊4sn⌋+q1⋅⌈4sn⌉=1⋅1+0⋅1=1.
- Let p2=1 and q2=1, then s2=p2⋅⌊4sn⌋+q2⋅⌈4sn⌉=1⋅1+1⋅1=2.
- Let p3=2 and q3=2, then s3=p3⋅⌊4sn⌋+q3⋅⌈4sn⌉=2⋅1+2⋅1=4.
Therefore, the answer is ∑x=14x⋅f(x)=1⋅1+2⋅2+3⋅3+4⋅3=26.
For the second test case:
- f(1)=f(2)=f(3)=1
- f(4)=3
- f(5)=f(6)=f(7)=f(8)=f(9)=4
For example, when x=3 we have f(3)=1 because there exist p4 and q4:
9=1cdotleftlfloor9over3rightrfloor+2cdotleftlceil9over3rightrceil
It can be shown that it is impossible to find p1,p2,p3 and q1,q2,q3 that satisfy the conditions.
When x=5 we have f(5)=4 because there exist pi and qi as followings:
1 = 1 \\cdot\\left\\lfloor{9\\over 5}\\right\\rfloor + 0 \\cdot\\left\\lceil{9\\over 5}\\right\\rceil$$ $$2 = 0 \\cdot\\left\\lfloor{9\\over 5}\\right\\rfloor + 1 \\cdot\\left\\lceil{9\\over 5}\\right\\rceil$$ $$7 = 3 \\cdot\\left\\lfloor{9\\over 5}\\right\\rfloor + 2 \\cdot\\left\\lceil{9\\over 5}\\right\\rceil$$ $$9 = 3 \\cdot\\left\\lfloor{9\\over 5}\\right\\rfloor + 3 \\cdot\\left\\lceil{9\\over 5}\\right\\rceilTherefore, the answer is ∑x=19x⋅f(x)=158.
对于第一个测试用例,sn=4,函数 f(x) 的计算过程如下:
- f(1)=1
- ⌊1sn⌋=4,⌈1sn⌉=4。
- 可以证明,不存在满足条件的 p1,p2 和 q1,q2。
- 令 p3=1、q3=0,则 s3=p3⋅⌊1sn⌋+q3⋅⌈1sn⌉=1⋅4+0⋅4=4。
- f(2)=2
- ⌊2sn⌋=2,⌈2sn⌉=2。
- 可以证明,不存在满足条件的 p1 和 q1。
- 令 p2=1、q2=0,则 s2=p2⋅⌊2sn⌋+q2⋅⌈2sn⌉=1⋅2+0⋅2=2。
- 令 p3=0、q3=2,则 s3=p3⋅⌊2sn⌋+q3⋅⌈2sn⌉=0⋅2+2⋅2=4。
- f(3)=3
- ⌊3sn⌋=1,⌈3sn⌉=2。
- 令 p1=1、q1=0,则 s1=p1⋅⌊3sn⌋+q1⋅⌈3sn⌉=1⋅1+0⋅2=1。
- 令 p2=0、q2=1,则 s2=p2⋅⌊3sn⌋+q2⋅⌈3sn⌉=0⋅1+1⋅2=2。
- 令 p3=0、q3=2,则 s3=p3⋅⌊3sn⌋+q3⋅⌈3sn⌉=0⋅1+2⋅2=4。
- f(4)=3
- ⌊4sn⌋=1,⌈4sn⌉=1。
- 令 p1=1、q1=0,则 s1=p1⋅⌊4sn⌋+q1⋅⌈4sn⌉=1⋅1+0⋅1=1。
- 令 p2=1、q2=1,则 s2=p2⋅⌊4sn⌋+q2⋅⌈4sn⌉=1⋅1+1⋅1=2。
- 令 p3=2、q3=2,则 s3=p3⋅⌊4sn⌋+q3⋅⌈4sn⌉=2⋅1+2⋅1=4。
因此,答案为 ∑x=14x⋅f(x)=1⋅1+2⋅2+3⋅3+4⋅3=26。
对于第二个测试用例:
- f(1)=f(2)=f(3)=1
- f(4)=3
- f(5)=f(6)=f(7)=f(8)=f(9)=4
例如,当 x=3 时,有 f(3)=1,因为存在 p4 和 q4 满足:
9=1⋅⌊39⌋+2⋅⌈39⌉
可以证明,不存在满足条件的 p1,p2,p3 和 q1,q2,q3。
当 x=5 时,有 f(5)=4,因为存在如下 pi 和 qi:
1 = 1 \cdot\left\lfloor{9\over 5}\right\rfloor + 0 \cdot\left\lceil{9\over 5}\right\rceil$$ $$2 = 0 \cdot\left\lfloor{9\over 5}\right\rfloor + 1 \cdot\left\lceil{9\over 5}\right\rceil$$ $$7 = 3 \cdot\left\lfloor{9\over 5}\right\rfloor + 2 \cdot\left\lceil{9\over 5}\right\rceil$$ $$9 = 3 \cdot\left\lfloor{9\over 5}\right\rfloor + 3 \cdot\left\lceil{9\over 5}\right\rceil因此,答案为 ∑x=19x⋅f(x)=158。
输入解题思路,AI测评打分。不知道怎么写?