Submission #1141225

#TimeUsernameProblemLanguageResultExecution timeMemory
1141225tadashii74XOR (IZhO12_xor)C++20
0 / 100
575 ms320 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define fi first #define se second #define pii pair<ll, ll> typedef long long ll; typedef double du; using namespace std; using namespace __gnu_pbds; template<typename T> //tree < int , null_type , less , rb_tree_tag , tree_order_statistics_node_update > using ordered_set = tree<T, null_type, greater<>, rb_tree_tag, tree_order_statistics_node_update>; const ll N = 5e5 + 5, M = 1e7 + 10, mod = 1e9 + 7, mod1 = 1e9 + 11, LOG = 20; const du PI = 3.141592653589793238462643383279502884197; ll dx[]{1, 0, -1, 0, -1, 1, -1, 1}; ll dy[]{0, 1, 0, -1, 1, -1, -1, 1}; ll knight_dx[] = {-2, -2, 2, 2, -1, -1, 1, 1}; ll knight_dy[] = {1, -1, 1, -1, 2, -2, 2, -2}; ll k, ans = 1e17; /// Trie struct Node { ll ch[2]{}, mn = 1e17, sz{}; ll &operator[](ll x) { return ch[x]; } }; struct BT { vector<Node> trie; int newNode() { return trie.emplace_back(), trie.size() - 1; } BT() { newNode(); } void insert(ll x, ll idx, ll op) { ll u = 0; for (int i = 30; ~i; --i) { trie[u].mn = min(trie[u].mn, idx); ll v = x >> i & 1; if (!trie[u][v]) trie[u][v] = newNode(); u = trie[u][v]; trie[u].sz += op; } trie[u].mn = min(trie[u].mn, idx); } /// 1 0 0 1 /// /// 0 0 0 0 /// 6 1 1 0 /// 5 1 0 1 /// 7 1 1 1 /// tmp 1 0 0 ll query(ll x) { ll u = 0, res{}; for (int i = 30; ~i; --i) { ll b = x >> i & 1, best = trie[u][!b]; if (trie[best].sz) { ll tmp = res | (1 << i); if(tmp >= k) { ans = min(ans, trie[best].mn); u = trie[u][b]; }else res = tmp, u = best; } else u = trie[u][b]; } return res; } } bt; void solve(){ ll n, curr{}, y; cin >> n >> k; ll idx{}, mx_len{}; bt.insert(0, 0, 1); for (int i = 1; i <= n; ++i) { cin >> y; curr ^= y; ans = 1e17; bt.query(curr); ll len = i - ans; if(len > mx_len) mx_len = len, idx = ans + 1; else if(len == mx_len) idx = min(idx, 1ll * i); bt.insert(curr, i, 1); } cout << idx << ' ' << mx_len; } int main() { fast #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t = 1; // cin >> t; while (t--) { solve(); cout << '\n'; } }

Compilation message (stderr)

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