Submission #1042867

#TimeUsernameProblemLanguageResultExecution timeMemory
1042867khanhtbXOR (IZhO12_xor)C++14
0 / 100
1 ms348 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 = 5e3+8; struct Binary_Trie{ struct node{ int child[2], mx; node(){ child[0] = child[1] = -1; mx = 0; } }; 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].mx = id; } } int query(int x){ int ans = mod, u = 0; for(int i = 30; i >= 0; i--){ bool k = (x>>i&1); if(k){ if(trie[u].child[1] != -1) u = trie[u].child[1]; } else{ if(trie[u].child[1] != -1) ans = min(ans,trie[trie[u].child[1]].mx); if(trie[u].child[0] != -1) u = trie[u].child[0]; } } return ans; } } trie; void solve(){ int n,x;cin >> n >> x; int len = 0; pair<int,int> ans; int h = 0; trie.add(0,0); for(int i = 1; i <= n; i++){ int a;cin >> a; h ^= a; int pos = trie.query(x); if(i-pos > len){ ans = {pos+1,i}; len = i-pos; } trie.add(h,i); } cout << ans.fi-1 << " " << ans.se-1; } 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:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
xor.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...