QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741903#8050. Random PermutationUESTC_NLNSWA 347ms8052kbC++14773b2024-11-13 15:27:502024-11-13 15:28:01

Judging History

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

  • [2024-11-13 15:28:01]
  • 评测
  • 测评结果:WA
  • 用时:347ms
  • 内存:8052kb
  • [2024-11-13 15:27:50]
  • 提交

answer

#include<bits/stdc++.h>
#define lowbit(i) ((i)&(-i))
#define INF 0x3f3f3f3f
using namespace std;
const int N=300005;
int a[N],b[N],n,mx,pos[N],h[N+N];
long long ans;
void solve(int l,int r,int x){
	for(int i=l;i<=r;++i)b[i]=(a[i]<a[x])?-1:1;
	int s=0,as=0;
	for(int i=x;i>=l;--i)s+=b[i],h[s+n]++;
	s=0;
	for(int i=x+1;i<=r;++i)as+=h[n+2-s]+h[n+1-s],s+=b[i];
	as+=h[n+2-s]+h[n+1-s];
	s=0;
	for(int i=x;i>=l;--i)s+=b[i],h[s+n]--;
	ans+=1ll*as*a[x];
	// cerr<<a[x]<<" "<<as<<"\n";
}
signed main(){
	cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i],pos[a[i]]=i;
	for(int i=1;i<=n;++i){
		if(abs(i-n/2)<=500)solve(1,n,pos[i]);
		else solve(max(1,pos[i]-500),min(n,pos[i]+500),pos[i]);
	}cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7788kb

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 347ms
memory: 8052kb

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:

216871402464573

result:

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