QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#822806 | #8050. Random Permutation | EBeason# | WA | 2693ms | 4464kb | C++14 | 1.1kb | 2024-12-20 16:43:39 | 2024-12-20 16:43:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(1, 2, 3, "Ofast", "inline")
int n;
int a[300300];
long long ans=0;
//unordered_map<int,int> l;
struct likemap {
int ma[300300];
int& operator [] (int x) {
return ma[x+100000];
}
}l;
int getl(double p) {
if(abs(0.5-p)<=1e-9) return n;
else return log(5e-7) / (log(2)+log(p)/2+log(1-p)/2);
}
void solve(int x) {
int mxl=getl(1.0*a[x]/n);
l[0]=1;
int ll=max(1,x-mxl),rr=min(n,x+mxl);
for(int i=x-1,tmp=0;i>=ll;--i) {
if(a[i]<a[x]) --tmp;
else ++tmp;
l[tmp]=l[tmp]+1;
}
long long res=0;
res+=1ll*l[0]+1ll*l[1];
for(int i=x+1,tmp=0;i<=rr;++i) {
if(a[i]<a[x]) --tmp;
else ++tmp;
res+=1ll*l[-tmp]+1ll*l[-tmp+1];
}
ans+=res*a[x];
l[0]=0;
for(int i=x-1,tmp=0;i>=ll;--i) {
if(a[i]<a[x]) --tmp;
else ++tmp;
l[tmp]=0;
}
}
int main() {
scanf("%d",&n);
// n=300000;
for(int i=1;i<=n;++i) {
scanf("%d",&a[i]);
// a[i]=i;
}
// random_shuffle(a+1,a+n+1);
for(int i=1;i<=n;++i) {
solve(i);
// if(i%10000==0) cout<<i<<endl;
}
printf("%lld\n",ans);
return 0;
}
/*
4
1 4 2 3
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4012kb
input:
4 1 4 2 3
output:
22
result:
ok 1 number(s): "22"
Test #2:
score: -100
Wrong Answer
time: 2693ms
memory: 4464kb
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:
246032911350301
result:
wrong answer 1st numbers differ - expected: '250202478701074', found: '246032911350301'