QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#343185#1817. AND PermutationLaStataleBlueCompile Error//C++233.9kb2024-03-02 01:48:072024-03-02 01:48:07

Judging History

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

  • [2024-03-02 01:48:07]
  • 评测
  • [2024-03-02 01:48:07]
  • 提交

answer

#pragma ide diagnostic ignored "misc-no-recursion"

#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
typedef long double db;

#define TESTCASE 0

static void solve([[maybe_unused]] int tc) {
    int n;
    cin >> n;
    vector<long long> a(n);

    for (int i = 0; i < n; i++)cin >> a[i];

    if (n == 1) {
        cout << "0\n";
        return;
    }

    auto solve = [&](auto &solve, int pos, vector<long long> v) -> map<long long, long long> {
        if (v.size() == 0) {
            return map<long long, long long>();
        }
        if (v.size() == 2) {
            return map<long long, long long>{{v[0], v[1]},
                                             {v[1], v[0]}};
        }
        if (v.size() == 1) {
            return map<long long, long long>{{v[0], v[0]}};
        }

        //cout << pos << " bit\n";
        //for (auto i: v)cout << i << " ";
        //cout << "\n";
        map<long long, long long> res;
        int loop = -1;/*
        if (v.size() % 2 == 1) {
            for (int i = 0; i < (int) v.size(); i++) {
                if ((v[i] & ((1ll << pos) - 1)) == 0) {
                    res[v[i]] = v[i];
                    loop = v[i];
                    v.erase(v.begin() + i);

                    break;
                }
            }
        }*/
        //for (auto i: v)cout << i << " ";
        //cout << "\n";

        vector<long long> v0, v1;
        for (auto i: v) {
            if (i & (1ll << pos))v1.push_back(i);
            else v0.push_back(i);
        }

        map<long long, long long> sol0, sol1;
        sol0 = solve(solve, pos - 1, v0);
        sol1 = solve(solve, pos - 1, v1);

        map<long long, int> col;
        auto dfs = [&](auto &dfs, long long pos, int mode) -> void {
            //cout << pos << " dfs\n";
            if (col.find(pos) != col.end())return;
            col[pos] = mode;

            dfs(dfs, sol1[pos], mode ^ 1);

            if (sol0.find(pos ^ (1ll << pos)) != sol0.end())
                if (sol1.find(sol0[pos ^ (1ll << pos)] ^ (1ll << pos)) != sol1.end()) {
                    dfs(dfs, sol0[pos ^ (1ll << pos)] ^ (1ll << pos), mode ^ 1);
                }
        };

        for (auto i: v1)if (sol1[i] != i || (loop0==-1))dfs(dfs, i, 1);

        int loop0 = -1, loop1 = -1;

        for (auto [i, j]: sol0) {
            if (i == j)loop0 = i;
        }
        for (auto [i, j]: sol1) {
            if (i == j)loop1 = i;
        }

        if (loop0 != -1 && loop1 != -1) {
            sol0[loop0] = loop1;
            sol1[loop1] = loop0;
            loop0 = -1;
            loop1 = -1;
        }

        if (loop != -1 && loop1 != -1) {
            res[loop] = loop1;
            sol1[loop1] = loop;
            loop = -1;
            loop1 = -1;
        }

        if (loop0 != -1 && loop != -1) {
            sol0[loop0] = loop;
            res[loop] = loop0;
            loop0 = -1;
            loop = -1;
        }

        for (auto [i, j]: sol1) {
            if (col[i] == 1) {
                if(i==j){
int a=i^(1ll<<pos);
int b=sol0[a];

sol1[i]=b;
sol0[b]=i;
sol0[a]=a;
continue;
}
                int a = i ^ (1ll << pos);
                int b = sol0[a];
                sol1[i] = b;
                sol1[j] = a;
                sol0[a] = j;
                sol0[b] = i;
            }
        }


        for (auto [i, j]: sol0)res[i] = j;
        for (auto [i, j]: sol1)res[i] = j;
        return res;
    };    
auto sol = solve(solve, 59, a);

    for (int i = 0; i < n; i++) {
        cout << sol[a[i]] << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);

    if (const char *f = getenv("REDIRECT_STDOUT"); f) {
        freopen(f, "w", stdout);
    }

    int T = 1;
#if TESTCASE
    cin >> T;
#endif

    for (int t = 1; t <= T; t++) {
        solve(t);
    }

    return 0;
}

详细

answer.code: In lambda function:
answer.code:78:46: error: ‘loop0’ was not declared in this scope; did you mean ‘loop’?
   78 |         for (auto i: v1)if (sol1[i] != i || (loop0==-1))dfs(dfs, i, 1);
      |                                              ^~~~~
      |                                              loop
answer.code: In function ‘int main()’:
answer.code:146:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  146 |         freopen(f, "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~