QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#55511#1817. AND Permutationstasio6WA 2ms3592kbC++1.7kb2022-10-14 11:20:202022-10-14 11:20:23

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-14 11:20:23]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3592kb
  • [2022-10-14 11:20:20]
  • 提交

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.