제출 #514818

#제출 시각아이디문제언어결과실행 시간메모리
514818Be_dosXOR (IZhO12_xor)C++17
100 / 100
262 ms59436 KiB
#include <iostream> #include <cmath> #include <cctype> #include <vector> #include <algorithm> #include <set> #include <map> #include <deque> #include <stack> #include <unordered_set> #include <sstream> #include <cstring> #include <iomanip> #include <queue> #include <unordered_map> #include <random> #include <cfloat> #include <chrono> #include <bitset> #include <complex> #include <immintrin.h> #include <cassert> struct Node { Node* left = nullptr, *right = nullptr; int32_t min = INT32_MAX; }; #define BITS 30 void add(Node* root, int32_t x, int32_t val) { for(int32_t i = BITS - 1; i >= 0; i--) { root->min = std::min(root->min, val); if(x & (1 << i)) { if(root->right == nullptr) root->right = new Node; root = root->right; } else { if(root->left == nullptr) root->left = new Node; root = root->left; } } root->min = std::min(root->min, val); } int32_t get_min(Node* root, int32_t x, int32_t not_less_than) { int32_t ans = INT32_MAX; for(int32_t i = BITS - 1; i >= 0; i--) { if(not_less_than & (1 << i)) { ; } else { if(x & (1 << i)) { if(root->left != nullptr) ans = std::min(ans, root->left->min); } else { if(root->right != nullptr) ans = std::min(ans, root->right->min); } } if((not_less_than ^ x) & (1 << i)) { if(root->right == nullptr) return ans; root = root->right; } else { if(root->left == nullptr) return ans; root = root->left; } } ans = std::min(ans, root->min); return ans; } int main() { int32_t n, x; std::cin >> n >> x; int32_t* arr = new int32_t[n]; for(int32_t i = 0; i < n; i++) std::cin >> arr[i]; int32_t pref_xor = 0; Node* root = new Node; add(root, 0, 0); int32_t left = -1, right = -2; for(int32_t i = 0; i < n; i++) { pref_xor ^= arr[i]; int32_t opt = get_min(root, pref_xor, x); if(right - left + 1 < i + 1 - opt) { left = opt; right = i; } add(root, pref_xor, i + 1); } std::cout << left + 1 << " " << right - left + 1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...