QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#210102#5531. ICCCamillusCompile Error//C++204.2kb2023-10-11 01:31:252024-07-01 04:28:35

Judging History

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

  • [2024-07-01 04:28:35]
  • 管理员手动重测本题所有提交记录
  • [2023-10-11 01:31:25]
  • 评测
  • [2023-10-11 01:31:25]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;

struct dsu {
    vector<int> p;
    vector<vector<int>> d;

    dsu(int n) {
        p.resize(n);
        d.resize(n);
        for (int i = 0; i < n; i++) {
            p[i] = i;
            d[i] = {i};
        }
    }

    int get(int u) {
        if (u == p[u]) {
            return u;
        } else {
            return p[u] = get(p[u]);
        }
    }

    void join(int u, int v) {
        u = get(u);
        v = get(v);
        if (u == v) {
            return;
        }
        if (d[v].size() > d[u].size()) {
            swap(u, v);
        }
        p[v] = u;
        d[u].insert(d[u].end(), d[v].begin(), d[v].end());
        d[v].clear();
    }
};

random_device rd;
mt19937 rnd(rd());

int rand(int n) {
    return rnd() % n;
}

int rand(int l, int r) {
    return l + rand(r - l + 1);
}

vector<int> low_half(const vector<int> &A) {
    size_t x = A.size() >> 1;
    return vector<int>(A.begin(), A.begin() + x);
}

vector<int> top_half(const vector<int> &A) {
    size_t x = A.size() >> 1;
    return vector<int>(A.begin() + x, A.end());
}

bool query(const vector<int> &A, const vector<int> &B) {
    return query(A.size(), B.size(), A.data(), B.data());
}

//void setRoad(int u, int v) {
//    cout << "! " << u << " " << v << endl;
//}

void run(int n) {
    dsu Q(n + 1);

    auto loop = [&]() {
        map<int, vector<int>> A;
        for (int u = 1; u <= n; u++) {
            A[Q.get(u)].push_back(u);
        }

        vector<vector<int>> B;
        B.reserve(A.size());

        for (const auto &[a, b] : A) {
            B.push_back(b);
        }

        int m = (int)B.size();

        auto get = [&](const vector<int> &p) -> vector<int> {
            vector<int> Q;
            for (int i : p) {
                Q.insert(Q.end(), B[i].begin(), B[i].end());
            }
            return Q;
        };

        int x = 0;
        vector<int> x0, x1;

        for (int i = 0; i <= __lg(m); i++) {
            vector<int> p0, p1;

            for (int j = 0; j < m; j++) {
                if (bitset<32>(j)[i] == 0) {
                    p0.push_back(j);
                } else {
                    p1.push_back(j);
                }
            }

            if (query(get(p0), get(p1))) {
                x1.push_back(i);
                x ^= 1 << i;
            } else {
                x0.push_back(i);
            }
        }

        int u = 0;

        for (int i : x0) {
            vector<int> p0, p1;
            for (int j = 0; j < m; j++) {
                if (bitset<32>(j)[i] == 1 && bitset<32>(j)[x1.front()] == 0) {
                    p0.push_back(j);
                }
                if (bitset<32>(j)[i] == 1 && bitset<32>(j)[x1.front()] == 1) {
                    p1.push_back(j);
                }
            }
            if (query(get(p0), get(p1))) {
                u |= 1 << i;
            }
        }

        for (int i : x1) {
            if (i == x1.front()) {
                continue;
            }
            vector<int> p0, p1;
            for (int j = 0; j < m; j++) {
                if (bitset<32>(j)[i] == 0 && bitset<32>(j)[x1.front()] == 0) {
                    p0.push_back(j);
                }
                if (bitset<32>(j)[i] == 1 && bitset<32>(j)[x1.front()] == 1) {
                    p1.push_back(j);
                }
            }
            if (!query(get(p0), get(p1))) {
                u ^= 1 << i;
            }
        }

        int v = x ^ u;

        auto a = get({u});
        auto b = get({v});

        while (b.size() != 1) {
            if (query(a, low_half(b))) {
                b = low_half(b);
            } else {
                b = top_half(b);
            }
        }

        while (a.size() != 1) {
            if (query(low_half(a), b)) {
                a = low_half(a);
            } else {
                a = top_half(a);
            }
        }

        setRoad(a.front(), b.front());
        Q.join(a.front(), b.front());
    };

    for (int i = 0; i < n - 1; i++) {
        loop();
    }
}
//
//int main() {
//    int n;
//    cin >> n;
//    run(n);
//}

詳細信息

answer.code: In function ‘bool query(const std::vector<int>&, const std::vector<int>&)’:
answer.code:62:24: error: invalid initialization of reference of type ‘const std::vector<int>&’ from expression of type ‘std::vector<int>::size_type’ {aka ‘long unsigned int’}
   62 |     return query(A.size(), B.size(), A.data(), B.data());
      |                  ~~~~~~^~
answer.code:61:31: note: in passing argument 1 of ‘bool query(const std::vector<int>&, const std::vector<int>&)’
   61 | bool query(const vector<int> &A, const vector<int> &B) {
      |            ~~~~~~~~~~~~~~~~~~~^
answer.code: In lambda function:
answer.code:173:9: error: ‘setRoad’ was not declared in this scope
  173 |         setRoad(a.front(), b.front());
      |         ^~~~~~~