QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#741943#8050. Random PermutationUESTC_NLNSWA 625ms7720kbC++14845b2024-11-13 15:31:122024-11-13 15:31:30

Judging History

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

  • [2024-11-13 15:31:30]
  • 评测
  • 测评结果:WA
  • 用时:625ms
  • 内存:7720kb
  • [2024-11-13 15:31:12]
  • 提交

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";
}
int f(int x){
	if(x<=500)return n;
	if(x<=5000)return n/10;
	else return 500;
}
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){
		int y=f(abs(i-n/2));
		solve(max(1,pos[i]-y),min(n,pos[i]+y),pos[i]);
	}cout<<ans;
	return 0;
}
//4 1 4 2 3

详细

Test #1:

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

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 625ms
memory: 7660kb

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:

244643468065845

result:

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