QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799372#8050. Random Permutationgyydp123_LIMWA 268ms8272kbC++141.2kb2024-12-05 12:29:282024-12-05 12:29:29

Judging History

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

  • [2024-12-05 12:29:29]
  • 评测
  • 测评结果:WA
  • 用时:268ms
  • 内存:8272kb
  • [2024-12-05 12:29:28]
  • 提交

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)<=50) s+=(p[--L]>=i?1:-1);
    s=0;while(R+1<=n&&abs(s)<=50) 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));
    // For(j,L,R) debug("%d ",sum[j]);debug("\n");
    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;
    // debug("%d\n",tot);
    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: 7824kb

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 268ms
memory: 8272kb

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:

21037042975492

result:

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