Submission #1256475

#TimeUsernameProblemLanguageResultExecution timeMemory
1256475BahaminXOR (IZhO12_xor)C++20
100 / 100
81 ms23368 KiB
#include <bits/stdc++.h> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } #define ll long long #define ld long double #define all(a) (a).begin(), (a).end() #define sui cout.tie(NULL); cin.tie(NULL); ios_base::sync_with_stdio(false) const int MAX_N = 1e5 + 5; const int MOD = 1e9 + 7; const ll INF = 1e9; const ld EPS = 1e-9; const int LOG = 30; int n, x; int chs[MAX_N * LOG][2]; int mi[MAX_N * LOG]; int ind = 1; int child(int u, int p) { if (chs[u][p] == 0) chs[u][p] = ind++, mi[ind - 1] = INF; return chs[u][p]; } void add(int xx, int ind) { int now = 0; mi[now] = min(mi[now], ind); for (int i = LOG - 1; i >= 0; i--) { now = child(now, (xx & (1 << i)) ? 1 : 0); mi[now] = min(mi[now], ind); } } int get(int xx) { int now = 0; int re = INF; for (int i = LOG - 1; i >= 0; i--) { if (x & (1 << i)) { int ind1 = (xx & (1 << i)) ? 0 : 1; if (chs[now][ind1]) now = chs[now][ind1]; else return re; } else { int ind1 = ((xx & (1 << i)) ? 0 : 1); if (chs[now][ind1]) re = min(re, mi[child(now, ind1)]); if (chs[now][1 - ind1]) now = chs[now][1 - ind1]; else return re; } } re = min(re, mi[now]); return re; } void solve() { cin >> n >> x; int a[n]; int ps[n + 1]; ps[0] = 0; for (int i = 0; i < n; i++) cin >> a[i], ps[i + 1] = ps[i] ^ a[i]; mi[0] = INF; add(0, 0); pair<int, int> ans = make_pair(0, 0); for (int i = 0; i < n; i++) { add(ps[i + 1], i + 1); int num = get(ps[i + 1]); ans = max(ans, make_pair(i + 1 - num, -num - 1)); } cout << -ans.second << " " << ans.first << "\n"; } int main() { sui; int tc = 1; //cin >> tc; for (int t = 1; t <= tc; t++) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...