1 solutions
-
0
/* * __----~~~~~~~~~~~------___ * . . ~~//====...... __--~ ~~ * -. \_|// |||\\ ~~~~~~::::... /~ * ___-==_ _-~o~ \/ ||| \\ _/~~- * __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ * _-~~ .=~ | \\-_ '-~7 /- / || \ / * .~ .~ | \\ -_ / /- / || \ / * / ____ / | \\ ~-_/ /|- _/ .|| \ / * |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ * ' ~-| /| |-~\~~ __--~~ * |-~~-_/ | | ~\_ _-~ /\ * / \ \__ \/~ \__ * _--~ _/ | .-~~____--~-/ ~~==. * ((->/~ '.|||' -_| ~~-/ , . _|| * -_ ~\ ~~---l__i__i__i--~~_/ * _-~-__ ~) \--______________--~~ * //.-~~~-~_--~- |-------~~~~~~~~ * //.-~~~--\ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 神兽保佑 永无BUG */ /* * @Description: I want to be the weakest vegetable in the world! * @Author: I.Z. */ #include<bits/stdc++.h> using namespace std; #define MOD 998244353 #define speMOD 2933256077ll #define int long long #define pii pair<int,int> #define all(v) v.begin(),v.end() #define pb push_back #define REP(i,b,e) for(int i=(b);i<(int)(e);++i) #define over(x) {cout<<x<<endl;return;} #define lowbit(x) ((x)&(-(x))) #define cntbit(x) __builtin_popcount(x) #define rf(v) shuffle(all(v),sd); mt19937 sd(std::random_device{}()); int qpow (int a,int b,int m=MOD,int res=1){ a%=m; while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1; return res; } string YN(bool x,string Y="Yes",string N="No") { if(x){ return Y; } else { return N; } } int fac[2000005],inv[2000005]; void init(int n){ fac[0]=inv[0]=1; REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD; inv[n]=qpow(fac[n],MOD-2); for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD; REP(i,1,n+1)(inv[i]*=fac[i-1])%=MOD; } int binom(int x,int y){ return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD; } struct linear{ int k,b; int sum(int l,int r){return (k*(l+r)+b*2)%MOD*(r-l+1)%MOD;} }tag[2000005]; int seg[2000005]; int n; int a[500005]; int st[500005],tp; void build(int l,int r,int p){ seg[p]=0;tag[p]={(int)1e18,0}; if(l==r)return; int m=(l+r)>>1; build(l,m,p*2+1);build(m+1,r,p*2+2); } void pushdown(int l,int r,int m,int p){ if(tag[p].k==1e18)return; tag[p*2+1]=tag[p*2+2]=tag[p]; seg[p*2+1]=tag[p].sum(l,m);seg[p*2+2]=tag[p].sum(m+1,r); tag[p]={(int)1e18,0}; } void update(int l,int r,int s,int t,int p,linear val){ if(l<=s&&t<=r){ seg[p]=val.sum(s,t);tag[p]=val; return; } int m=(s+t)>>1; pushdown(s,t,m,p); if(m>=l)update(l,r,s,m,p*2+1,val); if(m<r)update(l,r,m+1,t,p*2+2,val); seg[p]=seg[p*2+1]+seg[p*2+2]; } int query(int l,int r,int s,int t,int p){ if(l<=s&&t<=r)return seg[p]; int m=(s+t)>>1,res=0; pushdown(s,t,m,p); if(m>=l)res=query(l,r,s,m,p*2+1); if(m<r)res+=query(l,r,m+1,t,p*2+2); if(res>=MOD)res-=MOD; return res; } void Main() { cin>>n;init(n); REP(i,0,n)cin>>a[i]; cout<<a[0]%MOD<<' '; st[tp++]=0; build(0,n-1,0); REP(i,1,n){ while(tp>1&&(a[st[tp-2]]-a[st[tp-1]])*(st[tp-1]-i)<(a[st[tp-1]]-a[i])*(st[tp-2]-st[tp-1]))--tp; st[tp++]=i; int y=st[tp-2]; int x=(MOD+(a[i]-a[y])%MOD*inv[i-y]%MOD)%MOD; update(st[tp-2],i-1,0,n-1,0,{x,(a[y]+MOD-x*y%MOD)%MOD}); int ans=(a[0]+a[i])*2+query(1,i,0,n-1,0); cout<<ans%MOD*(MOD+1)/2%MOD*inv[i+1]%MOD<<' '; } cout<<endl; } void TC() { int tc=1; while(tc--){ Main(); cout.flush(); } } signed main() { freopen("walk.in","r",stdin); freopen("walk.out","w",stdout); return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0; } /* 1. CLEAR the arrays (ESPECIALLY multitests) 2. DELETE useless output */
- 1
Information
- ID
- 2917
- Time
- 2000ms
- Memory
- 512MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 2
- Accepted
- 2
- Uploaded By