QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#440329#8049. Equal Sumsrotcar07WA 1ms4132kbC++141006b2024-06-13 16:24:532024-06-13 16:24:53

Judging History

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

  • [2024-06-13 16:24:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4132kb
  • [2024-06-13 16:24:53]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
constexpr int M=3e5+5;long long ans,cnt;
int n,block,len,p[M],a[M],buc[M<<1];
int read(){
    int x=0;char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}
double fun(double p,double eps){
    return min(1e9,fabs(p-0.5)<1e-9?1e9:log(eps)/(log(2)+log(p)/2+log(1-p)/2));
} mt19937 mt(time(NULL));
int main(){ n=read();
    for (int i=1;i<=n;i++) p[i]=read();
    for (int i=1;i<=n;i++){
        len=fun(1.*p[i]/n,1e-6);
        int l=max(1,i-len),r=min(n,i+len); a[l-1]=r-l+1;
        for (int k=l;k<=r;k++) a[k]=a[k-1]+(p[k]>p[i]?1:-1);
			#pragma GCC unroll 8
        for (int k=l;k<=i;k++) buc[a[k-1]]++; long long sum=0;
			#pragma GCC unroll 8
        for (int k=i;k<=r;k++) sum+=buc[a[k]]+buc[a[k]+1];
        ans+=1ll*p[i]*sum;cnt+=sum;
			#pragma GCC unroll 8
        for (int k=l;k<=i;k++) buc[a[k-1]]=0;
    }
    printf("%lld\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4132kb

input:

2 3
1 2
2 3
1 4
2 2
1 3

output:

5

result:

wrong answer 1st numbers differ - expected: '2', found: '5'