제출 #768328

#제출 시각아이디문제언어결과실행 시간메모리
768328DylanSmithXOR (IZhO12_xor)C++17
100 / 100
131 ms27060 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x),end(x) #define lb(x,y) lower_bound(all(x),y)-begin(x) mt19937 rng; typedef struct node { int l, r; int mn; node() { l = r = -1; mn = INT_MAX; } } node; vector<node> tree(1); int add(int n) { int cur = 0; for (int i = 29; i >= 0; i--) { if ((n & 1 << i) == 0) { if (tree[cur].l == -1) { tree[cur].l = sz(tree); tree.emplace_back(); } cur = tree[cur].l; } else { if (tree[cur].r == -1) { tree[cur].r = sz(tree); tree.emplace_back(); } cur = tree[cur].r; } } return cur; } void solve() { int N, K; cin >> N >> K; vector<int> arr(N); for (int i = 0; i < N; i++) cin >> arr[i]; tree[add(0)].mn = -1; vector<int> pre(N); for (int i = 0; i < N; i++) { pre[i] = arr[i]; pre[i] ^= i == 0 ? 0 : pre[i - 1]; int u = add(pre[i]); tree[u].mn = min(tree[u].mn, i); } for (int i = sz(tree) - 1; i >= 0; i--) { if (tree[i].l != -1) tree[i].mn = min(tree[i].mn, tree[tree[i].l].mn); if (tree[i].r != -1) tree[i].mn = min(tree[i].mn, tree[tree[i].r].mn); } vector<int> res = {0, 0}; for (int i = 0; i < N; i++) { int cur = 0; int mn = INT_MAX; for (int j = 29; j >= 0; j--) { if (cur == -1) continue; if ((K & 1 << j) == 0) { if ((pre[i] & 1 << j) == 0) { if (tree[cur].r != -1) mn = min(mn, tree[tree[cur].r].mn); cur = tree[cur].l; } else { if (tree[cur].l != -1) mn = min(mn, tree[tree[cur].l].mn); cur = tree[cur].r; } } else { if ((pre[i] & 1 << j) == 0) { cur = tree[cur].r; } else { cur = tree[cur].l; } } } if (cur != -1) mn = min(mn, tree[cur].mn); if (mn == INT_MAX) continue; if (mn < i) { if (i - mn > res[1]) { res = {mn, i - mn}; } } } cout << (res[0] + 2) << " " << res[1] << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); rng = mt19937(chrono::steady_clock::now().time_since_epoch().count()); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...