QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#411014#7899. Say Hello to the FuturelgvcWA 284ms10060kbC++144.9kb2024-05-14 20:09:422024-05-14 20:09:45

Judging History

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

  • [2024-05-14 20:09:45]
  • 评测
  • 测评结果:WA
  • 用时:284ms
  • 内存:10060kb
  • [2024-05-14 20:09:42]
  • 提交

answer

#include <bits/stdc++.h>
#define MOD 998244353
int N,mr,a[200009],dp[200009],s[200009],s2[200009],ix[200009],aq[200009],
tp[200009],su[200009];
void sv(int l,int r) {
    if(l==r) return;
    int md=(l+r)>>1;
    sv(l,md);
    int at=0,aq=0;
    for(int i=md+1;i<=r;i++) {
        if(a[i]>at) {
            aq=at;
            at=a[i];
        } else aq=std::max(aq,a[i]);
        s[i]=at;
        s2[i]=aq;
    }
    at=0;aq=0;
    for(int i=md;i>=l;i--) {
        if(a[i]>at) {
            aq=at;
            at=a[i];
        } else aq=std::max(aq,a[i]);
        s[i]=at;
        s2[i]=aq;
    }
    at=0;
    if(l) su[l-1]=0;
    su[l]=dp[l];
    for(int k=l+1;k<=md;k++) su[k]=(su[k-1]+dp[k])%MOD;
    for(int k=md+1;k<=r;k++) su[k]=0;
    for(int i=md;i>l;i--) {
        at=std::max(at,a[i]);
        if(at<a[md+1]) continue;
        int ll=md+1,rr=r;
        while(ll<rr) {
            mr=(ll+rr+1)>>1;
            if(s[mr]>at) rr=mr-1;else ll=mr;
        }
        int lx=std::max(at+i-1,md+1),rx=ll;
        if(lx>rx) continue;
        su[lx]=(su[lx]+dp[i-1])%MOD;
        if(rx!=r) su[rx+1]=(su[rx+1]+MOD-dp[i-1])%MOD;
    }
    for(int i=md+2;i<=r;i++) su[i]=(su[i]+su[i-1])%MOD;
    for(int i=md+1;i<=r;i++) dp[i]=(dp[i]+su[i])%MOD;
    at=0;s[md+1]=0;
    for(int i=md+1;i<=r;i++) {
        at=std::max(at,a[i]);
        int ll=l+1,rr=md+1;
        while(ll<rr) {
            mr=(ll+rr)>>1;
            if(s[mr]>=at) ll=mr+1;else rr=mr;
        }
        int lx=ll,rx=std::min(i-at+1,md+1);
        if(lx>rx) continue;
       dp[i]=(dp[i]+su[rx-1])%MOD;
        if(lx>1) dp[i]=(dp[i]+MOD-su[lx-2])%MOD;
     //  for(int k=lx;k<=rx;k++) dp[i]=(dp[i]+dp[k-1])%MOD;
    }
    sv(md+1,r);
}
void cl(int l,int r) {
    if(l==r) return;
    int md=(l+r)/2;
    cl(l,md);cl(md+1,r);
    int at=0,aqq=0,id;
    for(int i=md+1;i<=r;i++) {
        if(a[i]>at) {
            aqq=at;
            at=a[i];id=i;
        } else aqq=std::max(aqq,a[i]);
        s[i]=at;
        ix[i]=id;
        s2[i]=aqq;
    }
    at=0;aqq=0;
    for(int i=md;i>=l;i--) {
        if(a[i]>at) {
            aqq=at;
            at=a[i];
            id=i;
        } else aqq=std::max(aqq,a[i]);
        s[i]=at;
        ix[i]=id;
        s2[i]=aqq;
    }
    for(int i=md+2;i<=r;i++) {
        if(s[md]>=s2[i]) continue;
        int x=s2[i];
        int ll=l+1,rr=md;
        while(ll<rr) {
            mr=(ll+rr)/2;
            if(s[mr]>=x) ll=mr+1;else rr=mr;
        }
        ll=std::max(ll,i-s[i]+2);
        rr=md;
        rr=std::min(rr,i-s2[i]+1);
        for(int j=ll;j<=rr;j++) {
            aq[ix[i]]=(aq[ix[i]]+1ll*dp[N-i]*tp[j-1])%MOD;
        }
    }
    for(int i=md-1;i>=l;i--) {
        if(s[md+1]>s2[i]) continue;
        int x=s2[i];
        int ll=md+1,rr=r;
        while(ll<rr) {
            mr=(ll+rr+1)/2;
            if(s[mr]>x) rr=mr-1;else ll=mr;
        }
        ll=md+1;
        ll=std::max(ll,i+s2[i]-1);
        rr=std::min(rr,i+s[i]-2);
        for(int j=ll;j<=rr;j++) {
            aq[ix[i]]=(aq[ix[i]]+1ll*tp[i-1]*dp[N-j])%MOD;
        }
    }
    for(int i=md+1;i<=r;i++) {
        if(s[l]<s[i]) continue;
        int ll=l,rr=md,mr;
        while(ll<rr) {
            mr=(ll+rr+1)/2;
            if(s[mr]>=s[i]) {
                ll=mr;
            } else {
                rr=mr-1;
            }
        }
        int tpp=ll;
        ll=l,rr=md;
        while(ll<rr) {
            mr=(ll+rr)/2;
            if(s2[mr]>=s[i]) {
                ll=mr+1;
            } else {
                rr=mr;
            }
        }
        std::swap(tpp,rr);
        rr=std::min(rr,i-s[i]+1);
        if(tpp>rr) continue;
        ll=tpp;
        for(int j=ll;j<=rr;j++) {
            if(s[j]>i-j+1) {
                aq[ix[j]]=(aq[ix[j]]+1ll*tp[j-1]*dp[N-i])%MOD;
            }
        }
    }
    for(int i=md;i>=l;i--) {
        if(s[i]>=s[r]) continue;
        int ll=md+1,rr=r;
        while(ll<rr) {
            mr=(ll+rr)/2;
            if(s[i]<s[mr]) rr=mr;else ll=mr+1;
        }
        int tpp=ll;
        ll=md+1,rr=r;
        while(ll<rr) {
            mr=(ll+rr+1)/2;
            if(s[i]<s2[mr]) rr=mr-1;else ll=mr;
        }
        tpp=std::max(tpp,i+s[i]-1);
        if(tpp>rr) continue;
        ll=tpp;
        for(int j=ll;j<=rr;j++) {
            if(s[j]>j-i+1) {
                aq[ix[j]]=(aq[ix[j]]+1ll*tp[i-1]*dp[N-j])%MOD;
            }
        }
    }
}
signed main(void) {
    scanf("%d",&N);
    for(int i=1;i<=N;i++) {
        scanf("%d",&a[i]);
    }

    dp[0]=1;
    sv(0,N);
    std::reverse(a+1,a+N+1);
    for(int i=0;i<=N;i++) tp[i]=dp[i];
    memset(dp,0,sizeof(dp));dp[0]=1;
    sv(0,N);
    std::reverse(a+1,a+N+1);
    cl(0,N);
    for(int i=1;i<=N;i++) {
        printf("%lld ",(tp[N]+1ll*aq[i]+1ll*(a[i]==1?0:1)*tp[i-1]*dp[N-i])%MOD);
    }
}

詳細信息

Test #1:

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

input:

5
1 3 2 1 2

output:

3 6 3 3 6 

result:

ok 5 tokens

Test #2:

score: -100
Wrong Answer
time: 284ms
memory: 10060kb

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 826457499 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 199770th words differ - expected: '970202329', found: '78731990'