From 74f0ad020713cf7c339b41aaafd3285ca6d9e8a2 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 6 Jun 2022 20:48:36 +0800 Subject: [PATCH] =?UTF-8?q?3164.=20=E7=BA=BF=E6=80=A7=E5=9F=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/14619728/ --- AcWing/3164/3164.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 AcWing/3164/3164.cpp diff --git a/AcWing/3164/3164.cpp b/AcWing/3164/3164.cpp new file mode 100644 index 00000000..9f1194f9 --- /dev/null +++ b/AcWing/3164/3164.cpp @@ -0,0 +1,45 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n; +unsigned long long x, a[N], ans; + +inline void insert(unsigned long long x) { + for (int i = 63; ~i; i--) { + if (x & (1ull << i)) { + if (a[i]) { + x ^= a[i]; + } else { + a[i] = x; + + return; + } + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> x; + + insert(x); + } + + for (int i = 63; ~i; i--) { + if ((ans ^ a[i]) > ans) ans ^= a[i]; + } + + cout << ans << endl; + + return 0; +}