QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#313639 | #7899. Say Hello to the Future | zhouhuanyi | WA | 43ms | 30108kb | C++20 | 3.2kb | 2024-01-24 21:46:32 | 2024-01-24 21:46:33 |
Judging History
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 (j+a[i]-1<=i+sz[rs[i]])
Adder(s[j+a[i]-1],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]]<=j-a[i]+1)
Adder(A[j],MD2(s2[j-a[i]]-(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 (j+a[i]-1<=i+sz[rs[i]])
Adder(B[j],MD2(s2[j+a[i]]-s2[i+sz[rs[i]]+2]));
}
else
{
for (int j=i;j<=i+sz[rs[i]];++j)
if (i-sz[ls[i]]<=j-a[i]+1)
Adder(s[j-a[i]+1],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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4972kb
input:
5 1 3 2 1 2
output:
3 6 3 3 6
result:
ok 5 tokens
Test #2:
score: -100
Wrong Answer
time: 43ms
memory: 30108kb
input:
200000 15922 15391 11782 4758 1973 19909 16800 6438 3821 986 18599 2011 338 19886 12401 4169 11143 12665 3230 12565 15065 15056 5090 16908 13677 12634 11435 1425 8647 3876 10694 12256 3853 19901 5723 11065 6147 13613 13768 15794 14993 5819 8117 13871 14708 15099 7152 9810 14438 10557 3209 1265 13915...
output:
133957349 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59021946 59...
result:
wrong answer 1st words differ - expected: '157122482', found: '133957349'