제출 #1077790

#제출 시각아이디문제언어결과실행 시간메모리
1077790MyCodeXOR (IZhO12_xor)C++17
0 / 100
2 ms344 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = (int) 1e4 * 25 + 10; const int INF = (int) 1e18; int a[N], n; struct Node { int go[2], mx; bool term; Node() { fill(go, go + 2, -1); mx = -INF; term = false; } }; vector<Node> T; void add(int x, int ind) { int cur = 0; for (int bit = 30; bit >= 0; bit--) { T[cur].mx = max(T[cur].mx, ind); int c = ((x >> bit) & 1); if (T[cur].go[c] == -1) T[cur].go[c] = (int) T.size(), T.emplace_back(); cur = T[cur].go[c]; } T[cur].mx = max(T[cur].mx, ind); T[cur].term = true; } bool go(int cur, int c) { return T[cur].go[c] != -1; } int mx(int cur, int c) { return (go(cur, c) ? T[T[cur].go[c]].mx : -INF); } int get(int pref, int x) { int cur = 0, res = -INF; for (int bit = 30; bit >= 0; bit--) { int A = ((pref >> bit) & 1), B = ((x >> bit) & 1); if (A == B) { if (A == 0) res = max(res, mx(cur, 1)); if (!go(cur, 0)) break; cur = T[cur].go[0]; } else { if (A == 1) { res = max(res, mx(cur, 0)); if (!go(cur, 1)) break; cur = T[cur].go[1]; } else { if (!go(cur, 1)) break; cur = T[cur].go[1]; } } } return res; } int pref[N], x; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); freopen("c.in", "r", stdin); freopen("c.out", "w", stdout); T.emplace_back(); cin >> n >> x; for (int i = 0; i < n; i++) cin >> a[i]; pref[0] = 0; for (int i = 1; i <= n; i++) pref[i] = a[i - 1] ^ pref[i - 1]; int res = -INF, A = 0; for (int i = n; i >= 0; i--) { if (get(pref[i], x) > res) { res = get(pref[i], x); A = i; } add(pref[i], i); } for (int i = n; i >= 1; i--) { if ((pref[A] ^ pref[i]) >= x) { cout << A + 1 << " " << i - A; return 0; } } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

xor.cpp: In function 'int main()':
xor.cpp:77:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |     freopen("c.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
xor.cpp:78:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     freopen("c.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...