QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799378#8050. Random Permutationgyydp123_LIMWA 2375ms8352kbC++141.1kb2024-12-05 12:32:552024-12-05 12:32:55

Judging History

This is the latest submission verdict.

  • [2024-12-05 12:32:55]
  • Judged
  • Verdict: WA
  • Time: 2375ms
  • Memory: 8352kb
  • [2024-12-05 12:32:55]
  • Submitted

answer

#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);++i)
#define ForDown(i,j,k) for(int i=(j);i>=(k);--i)
#define Debug(fmt, args...) fprintf(stderr,"(func %s, line #%d): " fmt,__func__,__LINE__,##args),fflush(stderr)
#define debug(fmt, args...) fprintf(stderr,fmt,##args),fflush(stderr)
#define within :
#define LJY main
using namespace std;
typedef long long ll;
const int N=3e5+5;
inline int read(){
  char ch=getchar();int x=0,f=1;
  while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
  while(ch>='0'&&ch<='9')
    x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
  return x*f;
}
int n,p[N],pos[N];
int sum[N],cnt[N<<1];
signed LJY(){
  n=read();For(i,1,n) pos[p[i]=read()]=i;
  ll ans=0;
  For(i,1,n){
    int L=pos[i],R=pos[i],s=0;
    while(L-1>0&&abs(s)<=400) s+=(p[--L]>=i?1:-1);
    s=0;while(R+1<=n&&abs(s)<=400) s+=(p[++R]>=i?1:-1);
    sum[L-1]=0;For(j,L,R) sum[j]=sum[j-1]+(p[j]>i?1:(p[j]<i?-1:0));
    ll tot=0;
    ForDown(j,R,pos[i]) cnt[sum[j]+n]++;
    For(j,L-1,pos[i]-1) tot+=cnt[sum[j]+n]+cnt[sum[j]+1+n];
    For(j,pos[i],R) cnt[sum[j]+n]=0;
    ans+=tot*i;
  }printf("%lld",ans);
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7968kb

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 2375ms
memory: 8352kb

input:

100000
56449 21738 74917 44834 36187 96576 37204 28451 3444 13029 66039 8955 51445 30706 27229 37159 66052 16691 70389 29935 44984 3648 75082 73600 76621 28345 5298 37940 49412 85260 92029 18185 84398 10233 79227 98312 96649 30680 65206 38879 75397 26951 11294 58085 37297 97167 59252 44104 4058 3796...

output:

250179038528364

result:

wrong answer 1st numbers differ - expected: '250202478701074', found: '250179038528364'