F. Attraction Theory
time limit per test2 seconds
memory limit per test256 megabytes
Taylor Swift - Love Story (Taylor's Version)
⠀
There are 𝑛 people in positions 𝑝1,𝑝2,…,𝑝𝑛 on a one-dimensional coordinate axis. Initially, 𝑝𝑖=𝑖 for each 1≤𝑖≤𝑛.
You can introduce an attraction at some integer coordinate 𝑥 (1≤𝑥≤𝑛), and then all the people will move closer to the attraction to look at it.
Formally, if you put an attraction in position 𝑥 (1≤𝑥≤𝑛), the following changes happen for each person 𝑖 (1≤𝑖≤𝑛):
if 𝑝𝑖=𝑥, no change;
if 𝑝𝑖<𝑥, the person moves in the positive direction, and 𝑝𝑖 is incremented by 1;
if 𝑝𝑖>𝑥, the person moves in the negative direction, and 𝑝𝑖 is decremented by 1.
You can put attractions any finite number of times, and in any order you want.
It can be proven that all positions of a person always stays within the range [1,𝑛], i.e. 1≤𝑝𝑖≤𝑛 at all times.
Each position 𝑥 (1≤𝑥≤𝑛), has a value 𝑎𝑥 associated with it. The score of a position array [𝑝1,𝑝2,…,𝑝𝑛], denoted by 𝑠𝑐𝑜𝑟𝑒(𝑝), is ∑𝑛𝑖=1𝑎𝑝𝑖, i.e. your score increases by 𝑎𝑥 for every person standing at 𝑥 in the end.
Over all possible distinct position arrays 𝑝 that are possible with placing attractions, find the sum of 𝑠𝑐𝑜𝑟𝑒(𝑝). Since the answer may be large, print it modulo 998244353.
Input
Each test contains multiple test cases. The first line contains the number of test cases 𝑡 (1≤𝑡≤104). The description of the test cases follows.
The first line of each test case contains a single integer 𝑛 (1≤𝑛≤2⋅105).
The second line of each test case contains 𝑛 integers — 𝑎1,𝑎2,…,𝑎𝑛 (1≤𝑎𝑖≤109)
It is guaranteed that the sum of 𝑛 over all test cases does not exceed 2⋅105.
Output
For each test case, output a single line containing an integer: the sum of 𝑠𝑐𝑜𝑟𝑒(𝑝) over all possible distinct position arrays 𝑝 that are possible with placing attractions, modulo 998244353.
Example
inputCopy
7
1
1
2
5 10
3
1 1 1
4
1 1 1 1
4
10 2 9 7
5
1000000000 1000000000 1000000000 1000000000 1000000000
8
100 2 34 59 34 27 5 6
outputCopy
1
45
24
72
480
333572930
69365
Note
In the first test case, the only possible result is that person 1 stays at 1. The score of that is 𝑎1=1.
In the second test case, the following position arrays [𝑝1,𝑝2] are possible:
[1,2], score 15;
[1,1], score 10;
[2,2], score 20.
The sum of scores is 15+10+20=45.
In the third test case, the following position arrays [𝑝1,𝑝2,𝑝3] are possible:
[1,1,1];
[1,1,2];
[1,2,2];
[1,2,3];
[2,2,2];
[2,2,3];
[2,3,3];
[3,3,3].
Each has a score of 3, and thus the total sum is 24.解决这道题,用c++
最新发布