QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#405058 | #7937. Fast XORting | ucup-team992# | WA | 114ms | 6180kb | C++20 | 1.7kb | 2024-05-05 09:48:15 | 2024-05-05 09:48:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ar array
typedef int uci;
#define int long long
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ll long long
typedef pair<int, int> pii;
typedef vector<int> vi;
int n;
int count(int v, vector<int> &bit){
v++;
int out{};
while(v >= 1){
out += bit[v-1];
v ^= v&(-v);
}
return out;
}
void add(int v, vector<int> &bit){
v++;
while(v <= n){
bit[v-1]++;
v += v&(-v);
}
}
void solve(){
cin >> n;
vector<int> a(n);
for(int i{}; i < n; ++i)
cin >> a[i];
int c{};
int t = n;
while(t){
t >>= 1;
c++;
}
c--;
int out{};
int mask{};
for(int i = c; i >= 1; --i){
int totinv{};
int maxinv{};
for(int j{}; j < n; j += (1<<i)){
maxinv += (1<<i)*((1<<i)-1)/2;
int ones{};
for(int k = j; k < j+(1<<i); ++k){
if(a[k]&(1<<(i-1)))
ones++;
else{
totinv += ones;
}
}
}
maxinv -= totinv;
if(totinv >= maxinv+1){
for(int j{}; j < n; ++j){
a[j] ^= (1<<(i-1));
}
out++;
}
mask |= (1<<(i-1));
stable_sort(a.begin(), a.end(), [=](auto b, auto c){
return (b&mask) < (c&mask);
});
out += min(maxinv, totinv);
}
cout << out << '\n';
}
uci main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
8 0 1 3 2 5 4 7 6
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3592kb
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: 114ms
memory: 6180kb
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:
-12850424999
result:
wrong answer 1st numbers differ - expected: '17137565829', found: '-12850424999'