QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#55512 | #1817. AND Permutation | stasio6 | WA | 0ms | 3672kb | C++ | 1.7kb | 2022-10-14 11:21:05 | 2022-10-14 11:21:08 |
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[wyn[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
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3672kb
input:
6 0 1 4 5 2 6
output:
4 2 2 0 6 4 2 0 5 1
result:
wrong answer Output value not an unused input value.