1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<stack> #include<set> #include<bitset> #include<cmath> #include<assert.h> #define inc(i,l,r) for(int i=l;i<=r;i++) #define dec(i,l,r) for(int i=l;i>=r;i--) #define link(x) for(edge *j=h[x];j;j=j->next) #define mem(a) memset(a,0,sizeof(a)) #define ll unsigned long long #define succ(x) (1ll<<x) #define lowbit(x) (x&(-x)) #define sqr(x) ((x)*(x)) #define mid (x+y>>1) #define NM 500005 #define nm 400005 using namespace std; const double pi=acos(-1); const int inf=998244353; const double eps=1e-8; ll read(){ ll x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return f*x; }
inline void reduce(int&x){x+=x>>31&inf;} int n,a[NM]; vector<int>vec[NM],b[NM]; int l[NM],r[NM],tot,c[NM],cnt[NM]; int d[NM],len; inline ll qpow(ll x,ll t){ ll s=1; for(;t;t>>=1,x=x*x%inf)if(t&1)s=s*x%inf; return s; }
int main(){ n=read();inc(i,1,n)a[i]=read(); c[1]=l[1]=1;d[len=1]=a[1];vec[1].push_back(-a[1]);b[1].push_back(1); cnt[1]=1; inc(i,2,n){ if(d[len]<a[i])cnt[i]=++len;else cnt[i]=lower_bound(d+1,d+1+len,a[i])-d; d[cnt[i]]=a[i]; vec[cnt[i]].push_back(-a[i]); if(cnt[i]==1)l[i]=1; else{ int t=upper_bound(vec[cnt[i]-1].begin(),vec[cnt[i]-1].end(),-a[i])-vec[cnt[i]-1].begin(); if(t==0)l[i]=c[cnt[i]-1]; else reduce(l[i]=c[cnt[i]-1]-b[cnt[i]-1][t-1]); } reduce(c[cnt[i]]+=l[i]-inf); b[cnt[i]].push_back(c[cnt[i]]); } tot=qpow(c[len],inf-2); inc(i,1,len)vec[i].clear(),b[i].clear(),c[i]=0; dec(i,n,1)if(cnt[i]==len){ r[i]=1;c[len]++; vec[len].push_back(a[i]); b[len].push_back(c[len]); }else{ int t=upper_bound(vec[cnt[i]+1].begin(),vec[cnt[i]+1].end(),a[i])-vec[cnt[i]+1].begin(); if(t==0)r[i]=c[cnt[i]+1];else reduce(r[i]=c[cnt[i]+1]-b[cnt[i]+1][t-1]); vec[cnt[i]].push_back(a[i]); reduce(c[cnt[i]]+=r[i]-inf); b[cnt[i]].push_back(c[cnt[i]]); } inc(i,1,n)printf("%lld ",1ll*l[i]*r[i]%inf*tot%inf); putchar('\n'); return 0; }
|