QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#442041 | #7937. Fast XORting | HKOI0# | WA | 150ms | 11860kb | C++14 | 1.2kb | 2024-06-15 04:44:41 | 2024-06-15 04:44:41 |
Judging History
answer
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define int long long
using namespace std;
int a[1 << 18], ai[1 << 18];
struct BIT{
int bit[1 << 19];
void add(int p, int v) { ++p; for (int i = p; i < (1 << 19); i += i & -i) bit[i] += v; }
int qry(int p) { ++p; int ret = 0; for (int i = p; i; i -= i & -i) ret += bit[i]; return ret; }
} bit;
void solve(){
int n; cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i]; ai[a[i]] = i;
}
int inv = 0;
for (int i = n - 1; i >= 0; i--) {
inv += bit.qry(a[i]);
bit.add(a[i], 1);
}
for (int i = 0; i < n; i++) {
bit.add(a[i], -1);
}
int ans = 1;
for (int b = 0; (1 << b) < n; b++) {
int cnt = 0;
for (int j = 0; j < n; j += 1 << (b + 1)) {
for (int k = 0; k < (1 << b); k++) {
bit.add(ai[j + k], 1);
}
for (int k = 0; k < (1 << b); k++) {
cnt += bit.qry(ai[j + (1 << b) + k]);
}
for (int k = 0; k < (1 << b); k++) {
bit.add(ai[j + k], -1);
}
}
ans += min(cnt, (n / (1 << (b + 1)) * (1 << (b * 2))) - cnt);
}
cout << min(inv, ans) << '\n';
}
int32_t main(){
#ifndef LOCAL
cin.tie(0)->sync_with_stdio(false);
#endif
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9832kb
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: 9828kb
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: 150ms
memory: 11860kb
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:
-8632237941
result:
wrong answer 1st numbers differ - expected: '17137565829', found: '-8632237941'