QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#469569#7937. Fast XORtingrrWA 0ms3720kbC++14568b2024-07-09 20:15:072024-07-09 20:15:09

Judging History

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

  • [2024-07-09 20:15:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3720kb
  • [2024-07-09 20:15:07]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5*1e5;
int cnt[N],f[21][3];
int ans;
int n,m;
int ask(int x){
	int sum=0;
	for(int i=0;i<=__lg(n)-1;i++)sum+=f[i][x>>i&1];
	return sum;
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		int bit=1;
		for(int d=__lg(n)-1;~d;d--){
			cnt[bit]++;
			if(x>>d&1)f[d][1]+=cnt[bit<<1],bit=bit<<1+1;
			else f[d][0]+=cnt[bit<<1+1],bit=bit<<1; 
		}
		cnt[bit]++;
	}
	ans=ask(0);
	for(int i=1;i<n;i++)ans=min(ans,ask(i)+1);
	cout<<ans<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3720kb

input:

8
0 1 3 2 5 4 7 6

output:

14

result:

wrong answer 1st numbers differ - expected: '2', found: '14'