QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#55511 | #1817. AND Permutation | stasio6 | WA | 2ms | 3592kb | C++ | 1.7kb | 2022-10-14 11:20:20 | 2022-10-14 11:20:23 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
pair<int, int> org[1000002];
int tab[1000002];
int wsk[1000002];
int wyn[1000002];
int wej[1000002];
void rek(int p, int k, int bit) {
//cout << p << " " << k << " " << bit << "\n";
if (k == p) {
wsk[p] = p;
return;
}
if (!((tab[p]&(1<<bit)) == 0 && (tab[k]&(1<<bit))!= 0)) {
rek(p, k, bit - 1);
return;
}
int s;
for (s = p; s <= k; s++) {
if ((tab[s]&(1<<bit)) != 0) {
rek(p, s - 1, bit - 1);
rek(s, k, bit - 1);
break;
}
}
int wskp = p, pot = (1 << bit);
for (int i = s; i <= k; i++) {
while (tab[wskp] + pot < tab[i])
wskp++;
swap(wsk[i], wsk[wskp]);
}
// for (int i = p; i <= k; i++) {
// cout << tab[i] << " ";
// }
// cout << "\n";
// for (int i = p; i <= k; i++) {
// cout << tab[wsk[i]] << " ";
// }
// cout << "\n\n";
}
int32_t main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> org[i].first;
org[i].second = i;
wej[i] = org[i].first;
}
sort(org, org+n);
for (int i = 0; i < n; i++) {
tab[i] = org[i].first;
}
rek(0, n - 1, 60);
for (int i = 0; i < n; i++) {
wyn[org[i].second] = tab[wsk[i]];
}
for (int i = 0; i < n; i++) {
if ((wej[i]&wej[wsk[i]]) != 0) {
cout << wej[i] << " " << wej[wsk[i]] << "\n";
}
}
for (int i = 0; i < n; i++) {
cout << wyn[i] << "\n";
}
}
// 0 1 4 5 2 6
// 6 2 1 4 0 5
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3592kb
input:
6 0 1 4 5 2 6
output:
1 5 5 4 6 4 2 0 5 1
result:
wrong answer Bit and of corresponding values not zero.