QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#522 | #313662 | #7899. Say Hello to the Future | zhouhuanyi | zhouhuanyi | Failed. | 2024-01-24 22:38:08 | 2024-01-24 22:38:10 |
Details
Extra Test:
Accepted
time: 22ms
memory: 43660kb
input:
199999 100000 100001 100002 100003 100004 100005 100006 100007 100008 100009 100010 100011 100012 100013 100014 100015 100016 100017 100018 100019 100020 100021 100022 100023 100024 100025 100026 100027 100028 100029 100030 100031 100032 100033 100034 100035 100036 100037 100038 100039 100040 100041...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 199999 tokens
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#313662 | #7899. Say Hello to the Future | zhouhuanyi | TL | 78ms | 41244kb | C++20 | 3.3kb | 2024-01-24 22:00:10 | 2024-01-24 22:43:45 |
answer
#include<iostream>
#include<cstdio>
#define N 300000
#define mod 998244353
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void Adder2(int &x,int d)
{
x+=d;
if (x<0) x+=mod;
return;
}
int MD(int x)
{
return x>=mod?x-mod:x;
}
int MD2(int x)
{
return x<0?x+mod:x;
}
int n,lg[N+1],a[N+1],ls[N+1],rs[N+1],sz[N+1],A[N+1],B[N+1],sw[N+1],sw2[N+1],s[N+1],s2[N+1],dque[N+1],top,ST[N+1][21],ans[N+1];
void dfs(int x)
{
if (ls[x]) dfs(ls[x]);
if (rs[x]) dfs(rs[x]);
sz[x]=sz[ls[x]]+sz[rs[x]]+1;
return;
}
int query(int l,int r)
{
if (l>r) return 0;
int lw=lg[r-l+1];
return max(ST[l][lw],ST[r-(1<<lw)+1][lw]);
}
void dfs2(int x)
{
int L,R,sl,sr,d;
if (ls[x]) dfs2(ls[x]);
if (rs[x]) dfs2(rs[x]);
if (sz[ls[x]]<=sz[rs[x]])
{
for (int i=x-sz[ls[x]];i<=x;++i)
{
L=max(x,i+query(i,x-1)-1),R=min(x+sz[rs[x]],i+a[x]-2);
if (L<=R)
{
if (L==x) Adder(ans[x],1ll*A[i-1]*B[x+1]%mod);
if (rs[x])
{
d=rs[x];
while (d)
{
sl=max(max(L,i+a[d]-1),d),sr=min(R,d+sz[rs[d]]);
if (sl<=sr) Adder(ans[x],1ll*A[i-1]*MD2(sw2[sr+1]-sw2[sl])%mod);
d=ls[d];
}
}
}
}
}
else
{
for (int i=x;i<=x+sz[rs[x]];++i)
{
L=max(x-sz[ls[x]],i-a[x]+2),R=min(x,i-query(x+1,i)+1);
if (L<=R)
{
if (R==x) Adder(ans[x],1ll*A[x-1]*B[i+1]%mod);
if (ls[x])
{
d=ls[x];
while (d)
{
sl=max(L,d-sz[ls[d]]),sr=min(min(R,i-a[d]+1),d);
if (sl<=sr) Adder(ans[x],1ll*MD2(sw[sr-1]-((sl-1>0)?sw[sl-2]:0))*B[i+1]%mod);
d=rs[d];
}
}
}
}
}
return;
}
int main()
{
for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
n=read();
for (int i=1;i<=n;++i)
{
ST[i][0]=a[i]=read();
while (top&&a[dque[top]]<a[i]) ls[i]=dque[top],top--;
if (top) rs[dque[top]]=i;
dque[++top]=i;
}
for (int i=1;i<=lg[n];++i)
for (int j=1;j+(1<<i)-1<=n;++j)
ST[j][i]=max(ST[j][i-1],ST[j+(1<<(i-1))][i-1]);
dfs(dque[1]),A[0]=s2[0]=1;
for (int i=1;i<=n;++i)
{
if (sz[ls[i]]<=sz[rs[i]])
{
for (int j=i-sz[ls[i]];j<=i;++j)
if (max(j+a[i]-1,i)<=i+sz[rs[i]])
Adder(s[max(j+a[i]-1,i)],A[j-1]),Adder2(s[i+sz[rs[i]]+1],-A[j-1]);
}
else
{
for (int j=i;j<=i+sz[rs[i]];++j)
if (i-sz[ls[i]]<=min(j-a[i]+1,i))
Adder(A[j],MD2(s2[min(j-a[i]+1,i)-1]-(i-sz[ls[i]]-1>0?s2[i-sz[ls[i]]-2]:0)));
}
Adder(s[i],s[i-1]),Adder(A[i],s[i]),s2[i]=MD(s2[i-1]+A[i]);
}
for (int i=0;i<=n+1;++i) s[i]=s2[i]=0;
B[n+1]=s2[n+1]=1;
for (int i=n;i>=1;--i)
{
if (sz[ls[i]]<=sz[rs[i]])
{
for (int j=i-sz[ls[i]];j<=i;++j)
if (max(j+a[i]-1,i)<=i+sz[rs[i]])
Adder(B[j],MD2(s2[max(j+a[i]-1,i)+1]-s2[i+sz[rs[i]]+2]));
}
else
{
for (int j=i;j<=i+sz[rs[i]];++j)
if (i-sz[ls[i]]<=min(j-a[i]+1,i))
Adder(s[min(j-a[i]+1,i)],B[j+1]),Adder2(s[i-sz[ls[i]]-1],-B[j+1]);
}
Adder(s[i],s[i+1]),Adder(B[i],s[i]),s2[i]=MD(s2[i+1]+B[i]);
}
sw[0]=A[0],sw2[0]=B[0];
for (int i=1;i<=n+1;++i) sw[i]=MD(sw[i-1]+A[i]),sw2[i]=MD(sw2[i-1]+B[i]);
for (int i=1;i<=n;++i) ans[i]=A[n];
dfs2(dque[1]);
for (int i=1;i<=n;++i) printf("%d ",ans[i]);
puts("");
return 0;
}