제출 #683849

#제출 시각아이디문제언어결과실행 시간메모리
683849vovamrXOR (IZhO12_xor)C++17
100 / 100
129 ms46624 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fi first #define se second #define ll long long #define ld long double #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define pb push_back #define mpp make_pair #define ve vector using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; const ll inf = 1e18; const int iinf = 1e9; typedef pair<ll, ll> pll; typedef pair<int, int> pii; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); } template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); } pii answer = {-1, -1}; const int N = 2.5e5 * 30 + 100; int w = 0; int ch[N][2]; int mn[N]; inline void add(const int &x, const int &id) { int v = 0; for (int i = 29; ~i; --i) { int b = x >> i & 1; if (!ch[v][b]) ch[v][b] = ++w; chmin(mn[v], id); v = ch[v][b]; } chmin(mn[v], id); } inline void relax(const int &x, const int &need, const int &id) { int v = 0, ok = 1; for (int i = 29; ~i; --i) { int b = (x ^ need) >> i & 1; int tr = need >> i & 1; if (ch[v][b ^ 1] && !tr) { int ps = mn[ch[v][b ^ 1]]; chmax(answer, mpp(id - ps, -(ps + 1))); } if (!ch[v][b]) { ok = 0; break; } v = ch[v][b]; } if (ok) { int ps = mn[v]; chmax(answer, mpp(id - ps, -(ps + 1))); } } inline void solve() { for (int i = 0; i < N; ++i) mn[i] = iinf; int n, x; cin >> n >> x; ve<int> a(n); for (auto &i : a) cin >> i; int xr = 0; for (int i = 0; i < n; ++i) { xr ^= a[i]; if (xr >= x) { chmax(answer, mpp(i + 1, -0)); } relax(xr, x, i); add(xr, i); } cout << -answer.se + 1 << " " << answer.fi; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int q = 1; // cin >> q; while (q--) solve(); cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...