Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is n km.
Driving for a long time may be really difficult. Formally, if Leha has already covered ai≤ai+1. The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey.
Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from a2, and so on.
For example, if 3a1+2a2+a3+a4.
Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are p — the expected value of difficulty of his journey.
Obviously, 998244353.
The first line contains one number 1≤n≤106) — the distance from Moscow to Saratov.
The second line contains i-th kilometer after Leha has rested.
Print one number — 998244353.
2
1 2
5
4
1 3 3 7
60
理解题意题
https://www.cnblogs.com/Dillonh/p/9313493.html
公式推导过程 看这个博客
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int mod = 998244353; 5 const LL maxn = 1e6 + 7; 6 LL n,ans=0,a[maxn],b[maxn]; 7 int main() { 8 b[0]=1; 9 for (int i=1 ;i<maxn ;i++) b[i]=2*b[i-1]%mod; 10 scanf("%lld",&n); 11 for (int i=0 ;i<n ;i++) scanf("%lld",&a[i]); 12 for (int i=0 ;i<n ;i++) 13 ans=(ans+a[i]*((b[n-1-i]+((n-i-1)*b[n-1-1-i]%mod))%mod)%mod)%mod; 14 printf("%lld\n",ans); 15 return 0; 16 }