QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#302432#7899. Say Hello to the FutureYu_JieWA 471ms11044kbC++142.8kb2024-01-10 21:13:162024-01-10 21:13:17

Judging History

你现在查看的是最新测评结果

  • [2024-01-24 22:42:06]
  • hack成功,自动添加数据
  • (/hack/523)
  • [2024-01-10 21:13:17]
  • 评测
  • 测评结果:WA
  • 用时:471ms
  • 内存:11044kb
  • [2024-01-10 21:13:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=200005,P=998244353;
int n,a[N],f[N],g[N],ans[N],b[N],c[N],pos[N];
inline int rdc(int x) {return x<P?x:x-P;}
struct bit {
    int n,a[N];
    void add(int x,int v) {for(;x<=n;x+=x&-x) a[x]=rdc(a[x]+v);}
    int ask(int x) {int v=0; for(x=max(min(x,n),0);x;x-=x&-x) v=rdc(v+a[x]); return v;}
    void dfs(int x) {a[x]=0; for(int i=(x&-x)>>1;i;i>>=1) if(a[x-i]) dfs(x-i);}
    void clear() {for(int x=n;x;x-=x&-x) if(a[x]) dfs(x);}
} tr;
int read() {
	int x=0,f=1; char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-48;
	return x*f;
}
void dfs(int l,int r,int *f) {
    if(l==r) return ;
    int mid=l+r>>1;
    dfs(l,mid,f);
    vector<pair<int,int>> vc;
    for(int i=mid,j=1;i>=l;j=max(j,a[i]),i--) vc.push_back({i+j,i});
    sort(vc.begin(),vc.end()); tr.clear();
    for(int i=mid+1,j=a[i],k=0;i<=r;i++,j=max(j,a[i])) {
        for(;k<vc.size()&&i>=vc[k].first;k++) tr.add(vc[k].second+1,f[vc[k].second]);
        f[i]=rdc(f[i]+tr.ask(i-j+1));
    }
    dfs(mid+1,r,f);
}
void dfs2(int l,int r) {
    if(l==r) return ;
    int mid=l+r>>1;
    dfs2(l,mid); dfs2(mid+1,r);
    vector<pair<int,int>> vc;
    for(int i=mid+1,j=1;i<=r;j=max(j,a[i]),i++) vc.push_back({i-j,i});
    sort(vc.begin(),vc.end()); reverse(vc.begin(),vc.end()); tr.clear();
    int mx=1,nx=1,ps=0;
    for(int i=mid,j=0;i>=l;i--) {
        for(;j<vc.size()&&vc[j].first>=i+1;j++) tr.add(n+2-vc[j].second,g[vc[j].second]);
        b[i]=1ll*tr.ask(n+2-i-1-mx)*f[i]%P;
        if(mx==nx) pos[i]=0;
        else pos[i]=ps,c[i]=1ll*tr.ask(n+2-i-1-nx)*f[i]%P;
        if(a[i]>mx) nx=mx,mx=a[i],ps=i;
        else if(a[i]==mx) nx=a[i];
    }
    for(int i=l,j=0;i<=mid;i++) {
        ans[i]=rdc(ans[i]+j);
        j=rdc(j+b[i]);
        if(pos[i]) ans[pos[i]]=rdc(rdc(ans[pos[i]]-b[i]+P)+c[i]);
    }
    vc.clear();
    for(int i=mid,j=1;i>=l;j=max(j,a[i]),i--) vc.push_back({i+j,i});
    sort(vc.begin(),vc.end()); tr.clear();
    mx=1; nx=1; ps=0;
    for(int i=mid+1,j=0;i<=r;i++) {
        for(;j<vc.size()&&vc[j].first<=i-1;j++) tr.add(vc[j].second+1,f[vc[j].second]);
        b[i]=1ll*tr.ask(i-1-mx+1)*g[i]%P;
        if(mx==nx) pos[i]=0;
        else pos[i]=ps,c[i]=1ll*tr.ask(i-1-nx+1)*g[i]%P;
        if(a[i]>mx) nx=mx,mx=a[i],ps=i;
        else if(a[i]==mx) nx=a[i];
    }
    for(int i=r,j=0;i>mid;i--) {
        ans[i]=rdc(ans[i]+j);
        j=rdc(j+b[i]);
        if(pos[i]) ans[pos[i]]=rdc(rdc(ans[pos[i]]-b[i]+P)+c[i]);
    }
}
int main() {
    n=read();
    for(int i=1;i<=n;i++) a[i]=read();
    tr.n=n+1;
    f[0]=1; dfs(0,n,f);
    reverse(a+1,a+n+1);
    g[0]=1; dfs(0,n,g);
    reverse(a+1,a+n+1); reverse(g,g+n+2);
    dfs2(0,n+1);
    for(int i=1;i<=n;i++) printf("%d ",ans[i]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7848kb

input:

5
1 3 2 1 2

output:

3 6 3 3 6 

result:

ok 5 tokens

Test #2:

score: -100
Wrong Answer
time: 471ms
memory: 11044kb

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:

157122482 826457499 826457499 826457499 826457499 444613792 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 ...

result:

wrong answer 6th words differ - expected: '826457499', found: '444613792'