QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#411032#7899. Say Hello to the FuturelgvcTL 682ms24988kbC++146.1kb2024-05-14 20:32:562024-05-14 20:32:57

Judging History

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

  • [2024-05-14 20:32:57]
  • 评测
  • 测评结果:TL
  • 用时:682ms
  • 内存:24988kb
  • [2024-05-14 20:32:56]
  • 提交

answer

#include <bits/stdc++.h>
#define MOD 998244353
#define lb(n) ((n)&(-(n)))
int N,mr,SIZ,a[200009],dp[200009],s[200009],s2[200009],ix[200009],aq[200009],
tp[200009],su[200009],stp[200009],sdp[200009],va[200009],p[200009];
bool cmp(int x,int y) {
    return va[x]<va[y];
}
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);
}
struct n_t{
    int a,b,c;
};
std::vector<n_t> t[200009];
int sg[200009];
void up(int n,int v) {
    while(n<=SIZ) {
        sg[n]=(sg[n]+v)%MOD;
        n+=lb(n);
    }
}
int q(int n) {
    int as=0;
    while(n) {
        as=(as+sg[n])%MOD;
        n-=lb(n);
    }
    return as;
}
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,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);
        if(ll>rr) continue;
        aq[ix[i]]=(aq[ix[i]]+1ll*dp[N-i]*(stp[rr-1]-(ll==1?0:stp[ll-2])+MOD))%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);
        if(ll>rr) continue;
        aq[ix[i]]=(aq[ix[i]]+1ll*tp[i-1]*(sdp[N-ll]-(rr==N?0:sdp[N-rr-1])+MOD))%MOD;
    }
    for(int i=l;i<=md;i++) {
        p[i]=i;
        va[i]=s[i]+i;
    }
    std::sort(p+l,p+md+1,cmp);
    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;
        int la=ll,lb=rr;
        ll=l;rr=md;
        if(va[p[md]]<i+2) continue;
        while(ll<rr) {
            mr=(ll+rr)/2;
            if(va[p[mr]]<i+2) ll=mr+1;
            else rr=mr; 
        }
        t[ll].push_back((n_t){la,lb,dp[N-i]});
//        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;
     //       }
     //   }
    }
    SIZ=md-l+1;
    for(int i=1;i<=SIZ;i++) sg[i]=0;
    for(int i=l;i<=md;i++) {
        for(int j=0;j<t[i].size();j++) {
            up(t[i][j].a-l+1,t[i][j].c);
            up(t[i][j].b-l+2,MOD-t[i][j].c);
        }
        t[i].clear();
        aq[ix[p[i]]]=(aq[ix[p[i]]]+1ll*tp[p[i]-1]*q(p[i]-l+1))%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);
    stp[0]=tp[0];
    sdp[0]=dp[0];
    for(int i=1;i<=N;i++) {
        stp[i]=(tp[i]+stp[i-1])%MOD;
        sdp[i]=(dp[i]+sdp[i-1])%MOD;
    }
    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: 3ms
memory: 9328kb

input:

5
1 3 2 1 2

output:

3 6 3 3 6 

result:

ok 5 tokens

Test #2:

score: 0
Accepted
time: 305ms
memory: 18508kb

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:

ok 200000 tokens

Test #3:

score: 0
Accepted
time: 295ms
memory: 18488kb

input:

200000
4065 9196 2588 18803 10818 17671 10483 13134 12147 19916 19382 19338 8864 7637 19542 14938 16362 7115 9159 9711 17907 17653 10175 3279 7471 3465 14016 13951 8676 2856 16709 5372 12237 18083 11052 16398 7140 9730 8800 18999 16808 8729 7608 6668 7049 6024 7892 18039 7278 12417 2440 13112 4039 5...

output:

47583147 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 345009231 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 370164779 3...

result:

ok 200000 tokens

Test #4:

score: 0
Accepted
time: 335ms
memory: 21920kb

input:

200000
1 1 1 1 4547 1 1 1 1 1 1 1 6329 1 1 19778 1 1 12258 1 1 1 1 1 18104 1 8123 1 329 1 1 1 1 1 1 1 1 4438 1 1 1 1 1 208 1 1 1 1 1 1 1 1 1 15603 1 1 1 1 1 1 1 1 1 1 5513 1 1 15427 1 1 1 1 1 1 1 18309 1 1 6333 1 1 1 1 1 1 1 1 1 13938 1 1 1 1 1 1 9229 1 1 1 1 1 1 1 1 1791 1 1 1 11747 1 1 1 1 8992 1 ...

output:

225508548 225508548 225508548 225508548 748768610 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 225508548 ...

result:

ok 200000 tokens

Test #5:

score: 0
Accepted
time: 320ms
memory: 22248kb

input:

200000
1 1 1 1 1 1 1 10166 1 1 9410 1 1 1 1 1 1 1 1 1 296 1 1 1 1 1 1 1 1 1 1 7392 4057 17616 1 1 1 1 3084 14799 1 1 13598 1 1 9848 1 1 1 1 1 8084 1 1 1 1 1 1 1 1 10519 1 1 1 1 1 14 1 1 1 1 1 1 1 1 1 1 14981 1 1 1 1 1 1 1 1 1 5144 7784 1 1 1 1 1 1 1 19661 1 14894 1 1 1 1 1 1 1 1 10449 1 1 1 16473 1 ...

output:

735167914 735167914 735167914 735167914 735167914 735167914 735167914 211149010 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 735167914 ...

result:

ok 200000 tokens

Test #6:

score: 0
Accepted
time: 388ms
memory: 23128kb

input:

200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 1 6 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 1 1 1 1 6 1 1 1 2397 1 1 3 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 4 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 415221870 450552969 425969980 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 450552969 ...

result:

ok 200000 tokens

Test #7:

score: 0
Accepted
time: 370ms
memory: 23572kb

input:

200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9861 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1739 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11012 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1...

output:

723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 723674232 76256586 723674232 723674232 723674232 723674232 723674232 723674232 7...

result:

ok 200000 tokens

Test #8:

score: 0
Accepted
time: 682ms
memory: 24276kb

input:

200000
1 1 1 1 1 1 1 1 1 1 29 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 5 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 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8 1 1 1...

output:

529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 773664190 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 529842888 ...

result:

ok 200000 tokens

Test #9:

score: 0
Accepted
time: 640ms
memory: 24988kb

input:

200000
1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 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 5 1 1 1 1 2 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 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

806160702 806160702 806160702 806160702 806160702 364515698 806160702 806160702 806160702 806160702 806160702 806160702 806160702 806160702 806160702 806160702 806160702 806160702 806160702 806160702 806160702 806160702 331355896 806160702 806160702 806160702 806160702 806160702 806160702 806160702 ...

result:

ok 200000 tokens

Test #10:

score: -100
Time Limit Exceeded

input:

200000
1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 18 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 ...

output:


result: