제출 #1326975

#제출 시각아이디문제언어결과실행 시간메모리
1326975goats_9XOR (IZhO12_xor)C++20
0 / 100
0 ms332 KiB
/* Author: goats_9 */ #include <bits/stdc++.h> using namespace std; using ll = long long; struct Trie { enum { K = 2, D = 30 }; struct Node { vector<int> nxt = vector<int> (K, -1); int ts = 0; }; vector<Node> tr; Trie() : tr(1, Node()) {} void add(int x, int t) { int cur = 0; for (int j = D - 1; j >= 0; j--) { int b = x >> j & 1; if (tr[cur].nxt[b] == -1) { tr[cur].nxt[b] = (int)tr.size(); tr.push_back(Node()); } cur = tr[cur].nxt[b]; tr[cur].ts = max(t, tr[cur].ts); } } int query(int x, int l) { int ans = 0, cur = 0; for (int j = D - 1; j >= 0; j--) { int bx = x >> j & 1; int bl = l >> j & 1; int z = bx ^ 1; if (tr[cur].nxt[z] == -1) { z ^= 1; if (bl) return ans; cur = tr[cur].nxt[z]; } else { if (!bl) { ans = max(ans, tr[tr[cur].nxt[z]].ts); z ^= 1; if (tr[cur].nxt[z] == -1) return ans; } cur = tr[cur].nxt[z]; } } ans = max(ans, tr[cur].ts); return ans; } }; int main() { freopen("c.out", "w", stdout); freopen("c.in", "r", stdin); int n, x; cin >> n >> x; vector<int> a(n); for (auto& u : a) cin >> u; int z = 0; Trie trie; trie.add(z, n); int j = n, k = 0; for (int i = n - 1; i >= 0; i--) { z ^= a[i]; trie.add(z, i); int u = trie.query(z, x); if (u - i >= k) j = i, k = u - i; } cout << j + 1 << ' ' << k; return 0; }

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

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