Educational Codeforces Round 47 (Rated for Div. 2)E.Intercity Travelling

时间:2021-11-21 18:13:10

题目链接

大意:一段旅途长度N,中间可能存在N-1个休息站,连续走k长度时,疲劳值为a1+a2+...+aka_1+a_2+...+a_ka1​+a2​+...+ak​,休息后a1a_1a1​开始计,设PPP为疲劳值的期望,问p∗2n−1取模998244353p*2^{n-1}取模998244353p∗2n−1取模998244353的答案。

转自链接

求出每个疲劳值的使用概率,加在一起,乘一下就行了。

#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back using namespace std; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e6 +11;
const int mod = 998244353;
int n,a[N];
LL p[N],ans;
int main(){
ios::sync_with_stdio(false);
cin>>n;
p[0]=1;
for(int i=1;i<=n;i++)p[i]=(p[i-1]+p[i-1])%mod;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++){
ans=ans+(a[i]*(p[n-i]+p[n-i-1]*(n-i)%mod)%mod)%mod;
ans%=mod;
}
cout<<ans<<endl;
return 0;
}