QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#399026#8050. Random Permutation口嗨战神 (Binyang Jiang, Dayu Wang, Hejun Dong)Compile Error//C++141.2kb2024-04-25 20:55:322024-04-25 20:55:34

Judging History

This is the latest submission verdict.

  • [2024-04-25 20:55:34]
  • Judged
  • [2024-04-25 20:55:32]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define mpr make_pair
#define fi first
#define se second
#define db double
// #define int long long

char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p1=buf,p2=buf+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
void read(int&x){
    char c=GC;x=0;
    while(!isdigit(c))c=GC;
    while(isdigit(c))x=x*10+c-'0',c=GC;
}

const int maxn=3e5+10;
int n;
int p[maxn];
const int lim=1000;
int pos[maxn];

void solve(){
    read(n);
    for(int i=1;i<=n;i++)read(p[i]),pos[p[i]]=i,p[i]=1;
    ll ans=0;
    for(int i=1;i<=n;i++){
        int w=pos[i];
        p[w]=-1;
        if(abs(i-n/2)>50000)lim=300; else lim=1000;
        int cur=lim;
        vector<int>t(lim*2+10);
        for(int r=w;r<=n;r++){
            cur+=p[r];
            if(cur<0||cur>lim*2)break;
            t[cur]++;
        }
        cur=1+lim;
        for(int l=w;l;l--){
            cur+=p[l];
            if(cur<0||cur>=lim*2)break;
            ans+=1ll*(t[lim*2-cur]+t[lim*2-cur-1])*i;
        }
    }
    cout<<ans<<"\n";
    
}
signed main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:32:32: error: assignment of read-only variable ‘lim’
   32 |         if(abs(i-n/2)>50000)lim=300; else lim=1000;
      |                             ~~~^~~~
answer.code:32:46: error: assignment of read-only variable ‘lim’
   32 |         if(abs(i-n/2)>50000)lim=300; else lim=1000;
      |                                           ~~~^~~~~