제출 #1141236

#제출 시각아이디문제언어결과실행 시간메모리
1141236samy_nagyXOR (IZhO12_xor)C++20
0 / 100
1 ms320 KiB
#include <bits/stdc++.h> /// لتكن مشيئتك #define int long long #define ll long long using namespace std; const int N = 1e3 + 5, mod = 1e9 + 7;// 1e9+7, 998244353 struct BinaryTrie { struct Node { Node *ch[2]; int frq[2]; Node() { memset(ch, 0, sizeof ch); memset(frq, 0, sizeof frq); } }; Node *root = new Node(); int mxBit; BinaryTrie(int bt) { mxBit = bt; } void insert(int n) { Node *curr = root; for (int i = mxBit; ~i; --i) { int idx = ((1ll << i) & n ? 1 : 0); if (curr->ch[idx] == 0) { curr->ch[idx] = new Node(); } curr->frq[idx]++; curr = curr->ch[idx]; } } int Query(int x) { Node *curr = root; int res{}; for (int i = mxBit; ~i; --i) { int idx = ((1ll << i) & x ? 1 : 0); if (curr->ch[!idx] != 0) { curr = curr->ch[!idx]; res |= (1ll << i); } else { curr = curr->ch[idx]; } } return res; } }; void solve() { int n, x; cin >> n >> x; vector<int> pref; int c{}; for (int i = 0; i < n; ++i) { int u; cin >> u; c ^= u; pref.emplace_back(c); } map<int, int> mp; for (int i = 0; i < n; ++i) { if (!mp.count(pref[i]))mp[pref[i]] = i + 1; // cout << pref[i] << " "; } // cout << endl; BinaryTrie tree(32); tree.insert(0); mp[0] = 0; int k{}, st{}; for (int i = 0; i < n; ++i) { int prefR = pref[i]; int R = i + 1; int prefL = tree.Query(prefR); if (mp.count(prefL) and (prefL ^ prefR) >= x) { // cout << prefR << " " << R << " " << prefL << endl; int L = mp[prefL]; if (k < R - L + 1) { k = R - L + 1; st = L; } } tree.insert(prefR); } cout << st << " " << k; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int tc = 1; // cin >> tc; for (int i = 1; i <= tc; ++i) { solve(); // cout << "\n"; } }

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

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