Submission #1042877

#TimeUsernameProblemLanguageResultExecution timeMemory
1042877khanhtbXOR (IZhO12_xor)C++14
100 / 100
89 ms26284 KiB
#pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ld long double #define pb push_back #define pf push_front #define vi vector<ll> #define vii vector<vi> #define pll pair<ll, ll> #define vpll vector<pll> #define all(a) a.begin(), a.end() #define fi first #define se second using namespace std; const ll mod = 1e9+7; const ll inf = 2e18; const ll blocksz = 320; const ll N = 3e5+8; struct Binary_Trie{ struct node{ int child[2], mn; node(){ child[0] = child[1] = -1; mn = mod; } }; vector<node> trie = {node()}; void add(int x, int id){ int u = 0; for(int i = 30; i >= 0; i--){ bool k = (x>>i&1); if(trie[u].child[k] == -1){ trie[u].child[k] = trie.size(); trie.pb(node()); } u = trie[u].child[k]; trie[u].mn = min(trie[u].mn,id); } } int query(int x, int y){ int ans = mod, u = 0; for(int i = 30; i >= 0; i--){ bool k1 = (x>>i&1), k2 = (y>>i&1); if(k1){ if(trie[u].child[!k2] != -1) u = trie[u].child[!k2]; else return ans; } else{ if(trie[u].child[!k2] != -1) ans = min(ans,trie[trie[u].child[!k2]].mn); if(trie[u].child[k2] != -1) u = trie[u].child[k2]; else return ans; } } ans = min(ans,trie[u].mn); return ans; } } trie; void solve(){ int n,x;cin >> n >> x; int len = 0, ans = 1e9, h = 0; trie.add(0,0); for(int i = 1; i <= n; i++){ int a;cin >> a; h ^= a; int pos = trie.query(x,h); if(i-pos > len){ len = i-pos; ans = pos+1; } trie.add(h,i); } if(len == 0){ cout << -1 << " " << -1; return; } cout << ans << " " << len; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll T = 1; // cin >> T; for (ll i = 1; i <= T; i++) { solve(); cout << '\n'; } }

Compilation message (stderr)

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