제출 #571571

#제출 시각아이디문제언어결과실행 시간메모리
571571bojackduyXOR (IZhO12_xor)C++14
0 / 100
0 ms340 KiB
#include<iostream> #include<queue> #include<stack> #include<algorithm> #include<string.h> #define task #define size() size() * 1ll #define all(x) (x).begin(), (x).end() #define allr(x, sz) (x) + 1, (x) + 1 + sz #define pb push_back #define pii pair<int,int> #define fi first #define se second #define MASK(x) (1LL<<(x)) #define BIT(x,i) (((x)>>(i))&1) #define numbit(x) __builtin_popcountll(x) using namespace std; const int N = 1e6 + 1; const int M = 1e3 + 1; const long long mod = 1e9 + 7; const long long oo = 1e18 + 7; typedef vector<int> vi; typedef vector<pii> vii; typedef long long ll; template<class t> bool mini(t &x,t y) { if (x > y) { x = y; return 1; } return 0; } template<class t> bool maxi(t &x,t y) { if (x < y) { x = y; return 1; } return 0; } void file() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen(task.in, r, stdin); //freopen(task.out, w, stdout); return ; } int n, g, msb; int a[N]; struct node { int id; node *child[2]; node() { id = mod; child[0] = child[1] = nullptr; } }*root = new node(); void add(int x, int id) { node *p = root; for (int i = 29; i >= 0; i--) { if (p -> child[BIT(x, i)] == nullptr) p -> child[BIT(x, i)] = new node(); p = p -> child[BIT(x, i)]; mini(p -> id, id); } } int get(int x) { node *p = root; for (int i = 29; i >= 0; i--) { int l = mod, r = mod; if (p -> child[0] != nullptr) l = p -> child[0] -> id; if (p -> child[1] != nullptr) r = p -> child[1] -> id; if (l == r) { p = p -> child[1]; x ^= MASK(i); } else if (x >= g) { p = p -> child[l > r]; x ^= MASK(l > r); } else { if (r == mod) p = p -> child[0]; else { p = p -> child[1]; x ^= MASK(i); } } } return p -> id; } void solve(int test = -1) { cin >> n >> g; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] ^= a[i - 1]; } int ans = 0; pii res = pii(0, 0); add(a[0], 0); for (int i = 1; i <= n; i++) { int l = get(a[i]); if (maxi(ans, i - l)) { res = pii(l + 1, i - l); } add(a[i], i); } cout << res.fi << ' ' << res.se; } int32_t main() { file(); int T = 1; // cin >> T; for (int i = 1; i <= T; i++) { solve(i); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...