QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#524869 | #7937. Fast XORting | BuzzyBeez | WA | 83ms | 6704kb | C++14 | 918b | 2024-08-20 09:53:02 | 2024-08-20 09:53:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int a[1 << 18], b[1 << 18], cnt[1 << 18];
long long inv[18][2];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n; long long ans = 0, cur;
for (int i = 1; i <= n; ++i) cin >> a[i], b[i] = a[i];
for (int bit = 0; bit <= __lg(n); ++bit) {
for (int i = 1; i <= n; ++i) if (b[i] & (1 << bit)) b[i] ^= (1 << bit);
for (int i = 0; i < n; ++i) cnt[i] = 0;
for (int i = 1; i <= n; ++i)
if (!(a[i] & (1 << bit))) inv[bit][0] += cnt[b[i]];
else ++cnt[b[i]];
for (int i = 0; i < n; ++i) cnt[i] = 0;
for (int i = 1; i <= n; ++i)
if (a[i] & (1 << bit)) inv[bit][1] += cnt[b[i]];
else ++cnt[b[i]];
ans += inv[bit][0];
}
for (int x = 1; x < n; ++x) {
cur = 1;
for (int bit = 0; bit <= __lg(n); ++bit) if (x & (1 << bit)) cur += inv[bit][1];
ans = min(ans, cur);
}
cout << ans;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 3560kb
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: 83ms
memory: 6704kb
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:
65609
result:
wrong answer 1st numbers differ - expected: '17137565829', found: '65609'