QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469569 | #7937. Fast XORting | rr | WA | 0ms | 3720kb | C++14 | 568b | 2024-07-09 20:15:07 | 2024-07-09 20:15:09 |
Judging History
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'