From 08dbbe056dd51348a30ff26ed501aaed330a910e Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 5 Jun 2022 11:22:17 +0800 Subject: [PATCH] =?UTF-8?q?P3812=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91?= =?UTF-8?q?=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.luogu.com.cn/record/76955036 --- Luogu/P3812/P3812.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Luogu/P3812/P3812.cpp diff --git a/Luogu/P3812/P3812.cpp b/Luogu/P3812/P3812.cpp new file mode 100644 index 00000000..17e2d2f7 --- /dev/null +++ b/Luogu/P3812/P3812.cpp @@ -0,0 +1,50 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 55; + +int n; +long long x, a[N], ans; + +void insert(long long x) { + for (int i = 50; ~i; i--) { + if (!(x & (1ll << i))) continue; + + if (a[i]) { + x ^= a[i]; + } else { + for (int k = 0; k < i; k++) { + if (x & (1ll << k)) x ^= a[k]; + } + + for (int k = i + 1; k <= 50; k++) { + if (a[k] & (1ll << i)) a[k] ^= x; + } + + 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 = 0; i <= 50; i++) ans ^= a[i]; + + cout << ans << endl; + + return 0; +}