QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#819 | #448995 | #7899. Say Hello to the Future | zqs | Flamire | Failed. | 2024-09-12 17:48:44 | 2024-09-12 17:48:44 |
詳細信息
Extra Test:
Accepted
time: 42ms
memory: 17608kb
input:
199999 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951...
output:
7 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...
result:
ok 199999 tokens
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#448995 | #7899. Say Hello to the Future | Flamire | AC ✓ | 72ms | 15676kb | C++20 | 2.6kb | 2024-06-20 15:46:43 | 2024-06-20 15:46:44 |
answer
#include <bits/stdc++.h>
#define N 200011
#define pii pair<int,int>
#define s1 first
#define s2 second
using namespace std;
const int p=998244353;
int n,a[N];pii mx[21][N];
int f[N],df[N],sf[N],g[N],sg[N];
int L[N],L_[N],R[N],R_[N];
void proc()
{
memset(df,0,sizeof(df));
memset(f,0,sizeof(f));
memset(sf,0,sizeof(sf));
for(int i=1;i<=n;++i)L[i]=i-1,R[i]=i+1;
for(int i=1;i<=n;++i)while(L[i]&&a[L[i]]<=a[i])L[i]=L[L[i]];
for(int i=n;i;--i)while(R[i]<=n&&a[R[i]]<a[i])R[i]=R[R[i]];
f[0]=sf[0]=1;
for(int M=1;M<=n;++M)
{
int R=::R[M]-1,L=::L[M]+1;
if(R-M+1<=M-L)
{
for(int i=M;i<=R;++i)
{
int tl=L,tr=min(M,i-a[M]+1);
if(tl<=tr)f[i]=(0ll+f[i]+sf[tr-1]-(tl>1?sf[tl-2]:0))%p;
}
}
else
{
for(int i=L;i<=M;++i)
{
int tl=max(M,i+a[M]-1),tr=R;
if(tl<=tr)
{
df[tl]=(df[tl]+f[i-1])%p;
df[tr+1]=(df[tr+1]-f[i-1])%p;
}
}
}
df[M]=(df[M]+df[M-1])%p;
f[M]=(f[M]+df[M])%p;
sf[M]=(sf[M-1]+f[M])%p;
}
}
int prv[N],nxt[N];
pii ta[N];
void getLR()
{
for(int i=1;i<=n;++i)L[i]=i-1,R[i]=i+1;
for(int i=1;i<=n;++i)while(L[i]&&a[L[i]]<=a[i])L[i]=L[L[i]];
for(int i=n;i;--i)while(R[i]<=n&&a[R[i]]<a[i])R[i]=R[R[i]];
for(int i=1;i<=n;++i)ta[i]=pii(a[i],i);
sort(ta+1,ta+1+n,greater<pii >());
nxt[n+1]=n+1;
for(int i=1;i<=n;++i)
{
int x=ta[i].s2;
prv[x]=L[x];
nxt[x]=R[x];
nxt[L[x]]=x;prv[R[x]]=x;
L_[x]=prv[prv[x]];R_[x]=nxt[nxt[x]];
}
}
int ans[N];
int calc(int l1,int r1,int l2,int r2,int llen,int rlen)
{
int ans=0;
if(r1-l1+1<=r2-l2+1)
{
for(int i=l1;i<=r1;++i)
{
int tl=max(l2,i+llen-1),tr=min(r2,i+rlen-1);
if(tl<=tr)ans=(ans+1ll*f[i-1]*(sg[tr+1]-sg[tl]))%p;
}
}
else
{
for(int i=l2;i<=r2;++i)
{
int tl=max(l1,i-rlen+1),tr=min(r1,i-llen+1);
if(tl<=tr)ans=(ans+1ll*g[i+1]*(sf[tr-1]-(tl>1?sf[tl-2]:0)))%p;
}
}
return ans;
}
int main()
{
scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",a+i);
proc();
for(int i=0;i<=n;++i)g[i]=f[i];
reverse(a+1,a+1+n);
proc();
reverse(f,f+1+n+1);
for(int i=0;i<=n+1;++i)swap(f[i],g[i]);
reverse(a+1,a+1+n);
getLR();
sf[0]=f[0];sg[0]=g[0];
for(int i=1;i<=n+1;++i)sf[i]=(sf[i-1]+f[i])%p,sg[i]=(sg[i-1]+g[i])%p;
for(int i=1;i<=n;++i)ans[i]=f[n];
for(int i=1;i<=n;++i)
{
if(L[i])ans[L[i]]=(ans[L[i]]+calc(L_[i]+1,L[i],i,R[i]-1,a[i],a[L[i]]-1))%p;
if(R[i]<=n)
{
ans[R[i]]=(ans[R[i]]+calc(L[i]+1,i,R[i],R_[i]-1,a[i],a[R[i]]-1))%p;
}
}
for(int i=1;i<=n;++i)if(a[i]!=1)ans[i]=(ans[i]+1ll*f[i-1]*g[i+1])%p;
for(int i=1;i<=n;++i)printf("%d%c",(ans[i]%p+p)%p," \n"[i==n]);
fclose(stdin);fclose(stdout);return 0;
}