QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#469576#7937. Fast XORtingrrWA 47ms8676kbC++14616b2024-07-09 20:20:272024-07-09 20:20:28

Judging History

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

  • [2024-07-09 20:20:28]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:8676kb
  • [2024-07-09 20:20:27]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6;
int cnt[N],f[N][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.tie(0)->sync_with_stdio(0);
	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: 100
Accepted
time: 0ms
memory: 5780kb

input:

8
0 1 3 2 5 4 7 6

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 5768kb

input:

8
2 0 1 3 4 5 6 7

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 47ms
memory: 8676kb

input:

262144
47482 131703 90418 122675 166494 247529 196154 16950 66501 50357 246808 25929 10418 50538 26955 151884 63776 58023 20073 26544 74785 44064 41836 148543 87920 54172 3270 131495 130960 112122 167229 215767 77499 195004 21391 11039 168999 256346 109690 180904 172679 157200 78594 201857 52784 147...

output:

8563201475

result:

wrong answer 1st numbers differ - expected: '17137565829', found: '8563201475'