QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#440097 | #7937. Fast XORting | monkey8 | WA | 154ms | 5216kb | C++14 | 1.6kb | 2024-06-13 08:53:28 | 2024-06-13 08:53:28 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdio>
#include <utility>
#include <queue>
#include <math.h>
#include <set>
#include <bitset>
#include <cmath>
#include <bitset>
#include <stack>
#include <cstring>
#include <math.h>
#include <iomanip>
#include <unordered_map>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 262154;
int bit[MAXN];
int query(int idx){
int sum = 0;
while(idx > 0){
sum += bit[idx];
idx -= (idx & -idx);
}
return sum;
}
void update(int idx, int val){
while(idx < MAXN){
bit[idx] += val;
idx += (idx & -idx);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n; cin >> n;
vector<int> vals(n);
for(int i = 0; i < n; i++) {
cin >> vals[i];
}
int ans = 0;
int prev = 0;
for(int i = 0; i < n; i++) {
update(vals[i] + 1, 1);
prev += i - query(vals[i]);
}
ans = prev;
//cout << prev << '\n';
for(int j = round(log2(n) - 1); j >= 0; j--) {
for(int i = 0; i < n; i++) {
vals[i] ^= (1 << j);
}
for(int i = 1; i <= n; i++)
bit[i] = 0;
int curr = 0;
for(int i = 0; i < n; i++) {
update(vals[i] + 1, 1);
curr += i - query(vals[i]);
}
if(curr > prev) {
for(int i = 0; i < n; i++) {
vals[i] ^= (1 << j);
}
}
else prev = curr;
}
cout << min(ans, prev + 1) << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3652kb
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: 3696kb
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: 154ms
memory: 5216kb
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:
-42303355
result:
wrong answer 1st numbers differ - expected: '17137565829', found: '-42303355'