Submission #1176190

#TimeUsernameProblemLanguageResultExecution timeMemory
1176190InvMODXOR (IZhO12_xor)C++20
0 / 100
2095 ms1672 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define gcd __gcd #define sz(v) (int) v.size() #define pb push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define REV(i, a, b) for(int i = (a); i >= (b); i--) #define dbg(x) "[" #x " = " << (x) << "]" ///#define int long long using ll = long long; using ld = long double; using ull = unsigned long long; template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} const int N = 2e5+5; struct Trie{ struct Node{ Node* child[2]; int MnEnd; Node(): MnEnd(INT_MAX) { for(int i = 0; i < 2; i++){ child[i] = nullptr; } } }; typedef Node* pNode; pNode root; Trie(){ root = new Node(); } const int lg = 30; void addStr(int s, int pos){ pNode x = root; for(int i = lg; i >= 0; i--){ int c = (s >> i & 1); if(x->child[c] == nullptr) x->child[c] = new Node(); x = x->child[c]; } x->MnEnd = min(x->MnEnd, pos); } int query(pNode x, int current, int target, int height){ int MnPos = x->MnEnd; if(height < 0) return (current >= target ? MnPos : INT_MAX); for(int i = 0; i < 2; i++){ if(x->child[i] != nullptr){ int ncurrent = current ^ (i << height); MnPos = min(MnPos, query(x->child[i], ncurrent, target, height - 1)); } } return MnPos; } int find_answer(int pref, int target){ return query(root, pref, target, lg); } }; void solve() { int n,x; cin >> n >> x; vector<int> a(n + 1); FOR(i, 1, n) cin >> a[i], a[i] ^= a[i - 1]; Trie trie; trie.addStr(0, 0); int l = 0, r = 0; FOR(i, 1, n){ int pos = trie.find_answer(a[i], x); if(r - l < i - pos){ l = pos; r = i; } trie.addStr(a[i], i); } cout << l + 1 <<" " << r - l << "\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int t = 1; //cin >> t; while(t--) solve(); return 0; }

Compilation message (stderr)

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