제출 #1153618

#제출 시각아이디문제언어결과실행 시간메모리
1153618Peti4XOR (IZhO12_xor)C++20
0 / 100
2 ms320 KiB
#include <bits/stdc++.h> using namespace std; // #define int long long #define ll long long #define ld long double #define all(v) v.begin(), v.end() #define vi vector<int> #define pii pair<int, int> #define pll pair<ll, ll> const int N = 1e5+5, MOD = 1e9+7; const int M = 3, inf = INT_MAX; struct Node { int ch[2]{}, st{}; int &operator[](int x) { return ch[x]; } }; struct Trie { vector<Node> trie; Trie() {newNode();} int newNode () { trie.emplace_back(); return trie.size()-1; } void insert(int x, int ndx) { int u = 0; for (int i = M-1; ~i; --i) { bool b = x >> i & 1; if (!trie[u][b]) { trie[u][b] = newNode(); u = trie[u][b]; trie[u].st = ndx; } u = trie[u][b]; } } int query(int x, const int trg, int u = 0, int i = M-1, int xr = 0) { if (!~i) return 0; bool bx = x >> i & 1; int a = inf, b = inf; if (trie[u][0]) a = query(x, trg, trie[u][0], i-1, xr | (bx * (1<<i))); if (trie[u][1]) b = query(x, trg, trie[u][1], i-1, xr | ((bx^1) * (1<<i))); return min(a, b); } }; void solve() { int n, x; cin >> n >> x; Trie trie; int a = 0, b = 0, xr = 0; int e; cin >> e; xr = e; if (xr >= x) a = b = 1; trie.insert(e, 0); for (int i = 1; i < n; i++) { cin >> e; xr ^= e; if (xr >= x) a = 1, b = i+1; int ans = trie.query(xr, x); if (i-ans+1 > b) a = ans+2, b = i-ans; trie.insert(xr, i); } cout << a << ' ' << b << endl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("c.in", "r", stdin); freopen("c.in", "w", stdout); int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { solve(); } }

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

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