#P17334. 「TPOI-2D」Still Shining
「TPOI-2D」Still Shining
Background
My reflection brightest sunlight
Ran too far forgot my name
Falling tears still shine like dreams
Turning the pain to brighter days
Even if I lose my way
As feelings fade they stay the same
May be beaten when I'm broken
But I know I'm still shining
——Mayonazy "Still Shining".
Problem Description
Given an array of length .
For a permutation of , define $t(p)=\displaystyle\sum_{i=1}^{n}\sum_{j=\min(p_i,p_{i-1})}^{\max(p_i,p_{i-1})}a_j$. In particular, let .
Let be the set of all permutations of length . Find .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case:
The first line contains a positive integer .
The second line contains integers .
Output Format
Output lines, each containing one integer, which is the value of .
2
3
1 -2 3
66
-70 68 -92 74 52 53 -5 -94 1 68 -42 -14 25 6 51 -98 -72 94 -69 -3 -13 75 29 62 74 -33 -3 -32 75 29 -2 -79 -99 -81 14 42 92 -28 -67 -40 -96 35 8 -5 83 -81 5 95 -71 78 54 55 -77 6 71 18 71 -15 -74 98 69 -36 18 -33 10 -79
2
-5788
Hint
[Sample Explanation]
For the first test case, you can construct the permutation .
[Constraints]
This problem uses bundled testdata.
| Score | Special Property | |
|---|---|---|
| None |
For of the testdata, it is guaranteed that , , , and .
Translated by ChatGPT 5