QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567104#1817. AND PermutationBakry#WA 1ms3848kbC++142.0kb2024-09-16 07:12:382024-09-16 07:12:39

Judging History

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

  • [2024-09-16 07:12:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3848kb
  • [2024-09-16 07:12:38]
  • 提交

answer

#include <iostream>
#include <vector> 
#include <unordered_map>
#include <set>
#include <map> 
using namespace std;
#define int long long
std::pair<std::vector<int>, std::vector<int>>  solve(vector<int>& arr, int x) {
    if (x < 0 || arr.size() == 0) {
        return { vector<int>(arr.size(), 0), vector<int>(arr.size(), 0) };
    }
    // find the values which have bit x set
    // cout << x << endl;
    // return { {}, {} };
    vector<int> A, B;
    map<int, int> posB;
    for (int i = 0; i < arr.size(); i++) {
        if (arr[i] & (1 << x)) {
            A.push_back(arr[i] ^ (1LL << x));
        }
        else {
            B.push_back(arr[i]);
            posB[arr[i] & ((1LL << x) - 1)] = i;
        }
    }
    // return { {}, {} };
    // set<int> all;
    auto [A1, A2] = solve(A, x - 1);
    auto [B1, B2] = solve(B, x - 1);
    set<int> all;
    for (auto t : A1) {
        // all[t & ((1 << x) - 1)] = 0;
        all.insert(t);
    }

    // for (auto& t : A1) {
    //     t ^= (1 << x);
    // }
    for (auto& t : B1) {
        if (all.count(t)) {
            t ^= (1LL << x);
        }
    }
    // now for every B1 
    auto& res1 = A1;
    auto& res2 = A2;
    for (int& t : res2)
        t ^= (1LL << x);

    for (int i = 0; i < B1.size(); i++) {
        res1.push_back(B1[i]);
        res2.push_back(B2[i]);
    }

    return { res1, res2 };
}

main() {
    int n;
    cin >> n;

    vector<int> arr;
    unordered_map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        arr.push_back(x);
        mp[x] = i;

        // sort(arr.bsegin(), arr.end());
    }
    auto [A, B] = solve(arr, 59);
    // return 0;
    vector<int> E(n);
    // cout << A.size() << ' ' << B.size() << ' ';
    for (int i = 0; i < arr.size(); i++) {

        E[mp[A[i]]] = B[i];
        // cout << mp[arr[i]];
    }
    for (int i = 0; i < n; i++) {
        cout << E[mp[arr[i]]] << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3848kb

input:

6
0
1
4
5
2
6

output:

0
0
0
0
0
0

result:

wrong answer Output value not an unused input value.