QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375091#7899. Say Hello to the Futureucup-team197#Compile Error//C++204.0kb2024-04-02 21:27:412024-04-02 21:27:43

Judging History

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

  • [2024-04-02 21:27:43]
  • 评测
  • [2024-04-02 21:27:41]
  • 提交

answer

#include<iostream>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int N=2e5+5;
int n;
int a[N];
int bl[N],br[N];
ll p1[N],p2[N],s1[N],s2[N];
ll dx[N];
void aespa(ll* dp,ll* pref){
    dp[0]=1;
    ll cum=0;
    for(int i=1; i<=n ;i++){
        dx[i]=0;
    }
    for(int i=1; i<=n ;i++){
        int cl=bl[i];
        int cr=br[i];
        pref[i]=(dp[i-1]+pref[i-1])%mod;
        if(i-cl-1>=cr-i){
            for(int j=i; j<=cr ;j++){
                int tr1=max(cl,j-a[i]+2);
                int tr2=i;
                if(tr1<=tr2) dp[j]=(dp[j]-pref[tr2]+mod+pref[tr1-1])%mod;
            }
        }
        else{
            for(int j=cl; j<=i ;j++){
                int tr1=i;
                int tr2=min(j+a[i]-2,cr);
                //cout << "sex " << i << ' ' << j << ' ' << tr1 << ' ' << tr2 << endl;
                if(tr1<=tr2){
                    dx[tr1]=(dx[tr1]-dp[j-1]+mod)%mod;
                    dx[tr2+1]=(dx[tr2+1]+dp[j-1])%mod;
                }
            }
        }
        cum+=dx[i];
        dp[i]=(dp[i]+cum)%mod;
        dp[i]=(dp[i]+pref[i])%mod;
    }
}
vector<int>il[N],ir[N];

ll ans[N],dans[N];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n;
    a[0]=a[n+1]=1e9;
    stack<int>s;s.push(0);
    for(int i=1; i<=n ;i++){
        cin >> a[i];
        while(a[s.top()]<a[i]){
            br[s.top()]=i-1;
            s.pop();
        }
        bl[i]=s.top()+1;
        br[i]=n;
        s.push(i);
    }
    aespa(p1,p2);
    reverse(a+1,a+n+1);
    reverse(bl+1,bl+n+1);
    reverse(br+1,br+n+1);
    for(int i=1; i<=n ;i++){
        bl[i]=n+1-bl[i];
        br[i]=n+1-br[i];
        swap(bl[i],br[i]);
    }
    aespa(s1,s2);
    reverse(a+1,a+n+1);
    reverse(bl+1,bl+n+1);
    reverse(br+1,br+n+1);
    for(int i=1; i<=n ;i++){
        bl[i]=n+1-bl[i];
        br[i]=n+1-br[i];
        swap(bl[i],br[i]);
    }

    reverse(s1+1,s1+n+1);
    reverse(s2+1,s2+n+1);
    s1[n+1]=1;
    for(int i=1; i<=n ;i++){
        ir[bl[i]-1].push_back(i);
    }
    for(int i=n; i>=1 ;i--){
        il[br[i]+1].push_back(i);
    }
    int prv=0;
    for(int i=1; i<=n ;i++){
        int pt1=0,v1=0;
        int pt2=0,v2=0;
        while(true){
            int l1=bl[i],l2=i,r1=i,r2=br[i];
            if(pt1!=il[i].size()) l1=il[i][pt1]+1;
            if(pt1!=0) l2=il[i][pt1-1];
            if(pt2!=0) r1=ir[i][pt2-1];
            if(pt2!=ir[i].size()) r2=ir[i][pt2]-1;
            if(prv==1) r1=i;
            if(prv==2) l2=i;
            if(l2-l1<=r2-r1){
                //cout << "hi " << i << ' ' << l1 << ' ' << l2 << ' ' << r1 << ' ' << r2 << endl;
                int v=max(v1,v2);
                for(int j=l1; j<=l2 ;j++){
                    int tr1=max(r1,j+v-1);
                    int tr2=min(j+a[i]-2,r2);
                    //cout << "thonk " << j << ' ' << tr1 << ' ' << tr2 << endl;
                    if(tr1<=tr2) ans[i]=(ans[i]+p1[j-1]*(s2[tr1]-s2[tr2+1]+mod))%mod;
                }
            }
            else{
                //cout << "hj " << i << ' ' << l1 << ' ' << l2 << ' ' << r1 << ' ' << r2 << endl;
                int v=max(v1,v2);
                for(int j=r1; j<=r2 ;j++){
                    int tr1=max(j-a[i]+2,l1);
                    int tr2=min(l2,j-v+1);
                    if(tr1<=tr2) ans[i]=(ans[i]+s1[j+1]*(p2[tr2]-p2[tr1-1]+mod))%mod;
                }

            }
            //cout << "bleh " << ans[i] << endl;
            if(pt1==il[i].size() && pt2==ir[i].size()) break;
            if(pt1==il[i].size()) v2=a[ir[i][pt2++]],prv=2;
            else if(pt2==ir[i].size()) v1=a[il[i][pt1++]],prv=1;
            else if(a[il[i][pt1]]>a[ir[i][pt2]]) v2=a[ir[i][pt2++]],prv=2;
            else v1=a[il[i][pt1++]],prv=1;
        }
    }
    for(int i=1; i<=n ;i++){
        ll res=(p1[n]+ans[i])%mod;
        cout << res << ' ';
    }
    cout << '\n';
}

Details

answer.code: In function ‘int main()’:
answer.code:65:5: error: ‘reverse’ was not declared in this scope
   65 |     reverse(a+1,a+n+1);
      |     ^~~~~~~