QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#822867#8050. Random PermutationEBeason#WA 1ms4228kbC++141.0kb2024-12-20 17:06:512024-12-20 17:06:52

Judging History

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

  • [2024-12-20 17:06:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4228kb
  • [2024-12-20 17:06:51]
  • 提交

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;
int l[1001001];
double getl(double p) {
	if(abs(0.5-p)<1e-9) return 10*n;
	else return min(10.0*n,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=n;i>=ll;--i) {
		if(a[i]<a[x]) --tmp;
		else ++tmp;
		l[tmp]=l[tmp]+1;
	}
	int res=0;
	res+=l[0]+l[1];
	for(int i=x+1,tmp=n;i<=rr;++i) {
		if(a[i]<a[x]) ++tmp;
		else --tmp;
		res+=l[tmp]+l[tmp+1];
	}
	ans+=1ll*res*a[x];
	l[0]=0;
	for(int i=x-1,tmp=n;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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 4 2 3

output:

12

result:

wrong answer 1st numbers differ - expected: '22', found: '12'