[ABC326 E] Revenge of "The Salary of AtCoder Inc." 题解
Genius_Star · · 题解
题意:
Aoki 是 AtCoder 公司的一名员工,他这个月的工资由整数
首先,给他一个
然后,重复以下步骤,直到终止。
-
如果
x<y ,给他A_y 日元,让x=y 。 -
否则,终止进程。
掷一次骰子,让
青木这个月的工资就是通过这个流程支付的总金额。
求青木这个月的工资期望值,答案对
思路:
一道很简单的题,建议评黄。
我们考虑每一个
那么
所以我们可以直接扫一遍,用前缀和求出每一个
时间复杂度:
思路:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const ll N=300300;
const ll mod=998244353;
inline ll read(){
ll x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')
f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=(x<<1)+(x<<3)+(c^48);
c=getchar();
}
return x*f;
}
inline void write(ll x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9)
write(x/10);
putchar(x%10+'0');
}
ll n,x,ans,p;
ll qpow(ll a,ll b){
ll res=1;
while(b){
if(b&1)
res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
int main(){
n=read(),p=qpow(n,mod-2);
for(int i=1;i<=n;i++){
x=read();
ans=(ans+p*x)%mod;
p=(p+(p*qpow(n,mod-2))%mod)%mod;
}
write(ans);
return 0;
}