QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#440324 | #8049. Equal Sums | ship2077 | WA | 1ms | 6180kb | C++14 | 950b | 2024-06-13 16:22:18 | 2024-06-13 16:22:18 |
Judging History
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));
}
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,3e-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);
for (int k=l;k<=i;k++) buc[a[k-1]]++; long long sum=0;
for (int k=i;k<=r;k++) sum+=buc[a[k]]+buc[a[k]+1];
ans+=1ll*p[i]*sum;cnt+=sum;
for (int k=l;k<=i;k++) buc[a[k-1]]=0;
}
// cerr<<cnt<<":"<<1ll*n*(n+1)/2<<endl;
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: 6180kb
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'