Submission #873345

#TimeUsernameProblemLanguageResultExecution timeMemory
873345ObadaKhXOR (IZhO12_xor)C++17
100 / 100
279 ms86636 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; /*-------------------------*/ #define ll long long #define ld long double #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define Dracarys ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); template<typename T> using indexed_multiset = tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef pair<ll, int> pi; const int N = 2e5 + 10; const int infi = 1e9 + 10; const ll infl = 1e18 + 10; const int MOD = 1e9 + 7; const ld eps = 1e-9; string ScanString() { char ch[100000]; scanf("%s", ch); return ch; } const int LOG = 32; struct TrieNode { TrieNode *child[2]; int Cnt, End, index; TrieNode() { memset(child, 0, sizeof child); Cnt = End = 0; index = infi; } void add(int i, int id, bitset<LOG> &bt) { int cur = bt[i]; if (child[cur] == 0) child[cur] = new TrieNode(); child[cur]->Cnt++; if (child[cur]->index == infi)child[cur]->index = id; if (i == 0) { child[cur]->End++; return; } child[cur]->add(i - 1, id, bt); } void add(int num, int id) { Cnt++; if (index == infi)index = id; bitset<LOG> bt(num); add(LOG - 1, id, bt); } int Query(int i, bitset<LOG> p, bitset<LOG> l) { if (i == -1)return index; int curp = p[i], curl = l[i], ret = infi; if (!curp && !curl) { if (child[1])ret = child[1]->index; if (child[0])ret = min(ret, child[0]->Query(i - 1, p, l)); return ret; } if (curp && curl) { if (child[0])ret = child[0]->Query(i - 1, p, l); return ret; } if (!curp && curl) { if (child[1])return ret = child[1]->Query(i - 1, p, l); return ret; } if (curp && !curl) { if (child[0])ret = child[0]->index; if (child[1])ret = min(ret, child[1]->Query(i - 1, p, l)); return ret; } } int Query(int p, int l) { bitset<LOG> bt1(p), bt2(l); return Query(LOG - 1, bt1, bt2); } void clear() { for (int i = 0; i < 2; i++) if (child[i]) child[i]->clear(), delete child[i], child[i] = 0; } }; void RunTime(int Tc) { int n, k; cin >> n >> k; TrieNode *Root = new TrieNode(); int pref = 0; int res1 = 0, res2 = 0; Root->add(0, 0); for (int i = 1; i <= n; i++) { int x; cin >> x; pref ^= x; Root->add(pref, i); int val = Root->Query(pref, k); if (val == infi)continue; int tmp1 = val + 1, tmp2 = i - val; if (tmp2 > res2)res1 = tmp1, res2 = tmp2; else if (tmp2 == res2 && tmp1 < res1)res1 = tmp1, res2 = tmp2; } cout << res1 << ' ' << res2 << endl; Root->clear(); delete Root; } int main() { Dracarys int T = 1; //cin >> T; for (int Tc = 1; Tc <= T; Tc++) { RunTime(Tc); } return 0; }

Compilation message (stderr)

xor.cpp: In function 'std::string ScanString()':
xor.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%s", ch);
      |     ~~~~~^~~~~~~~~~
xor.cpp: In member function 'int TrieNode::Query(int, std::bitset<32>, std::bitset<32>)':
xor.cpp:78:5: warning: control reaches end of non-void function [-Wreturn-type]
   78 |     }
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...