From 49974f4d4ac5aed81578625652cbaeecc1979d42 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 6 Jun 2022 21:24:54 +0800 Subject: [PATCH] =?UTF-8?q?210.=20=E5=BC=82=E6=88=96=E8=BF=90=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/14620640/ --- AcWing/210/210.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 AcWing/210/210.cpp diff --git a/AcWing/210/210.cpp b/AcWing/210/210.cpp new file mode 100644 index 00000000..66679557 --- /dev/null +++ b/AcWing/210/210.cpp @@ -0,0 +1,78 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 65; + +int t, n, m, cnt; +unsigned long long x, k, a[N], p[N], ans; + +inline void insert(unsigned long long x) { + for (int i = 60; ~i; i--) { + if (x & (1ull << i)) { + if (a[i]) { + x ^= a[i]; + } else { + for (int k = 0; k < i; k++) { + if (x & (1ull << k)) x ^= a[k]; + } + + for (int k = i + 1; k <= 60; k++) { + if (a[k] & (1ull << i)) a[k] ^= x; + } + + a[i] = x; + return; + } + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> t; + + for (int c = 1; c <= t; c++) { + cout << "Case #" << c << ":" << endl; + + cnt = 0; + std::fill(a, a + 62, 0); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> x; + + insert(x); + } + + for (int i = 0; i <= 60; i++) { + if (a[i]) p[cnt++] = a[i]; + } + + cin >> m; + + while (m--) { + cin >> k; + + if (cnt != n) k--; + + if (k >= (1ull << cnt)) { + cout << -1 << endl; + } else { + ans = 0; + + for (int i = 0; i < cnt; i++) { + if (k & (1ull << i)) ans ^= p[i]; + } + + cout << ans << endl; + } + } + } + return 0; +}