Submission #1192553

#TimeUsernameProblemLanguageResultExecution timeMemory
1192553stefanopulosXOR (IZhO12_xor)C++20
100 / 100
74 ms23368 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ldb,ldb> pdd; #define ff(i,a,b) for(int i = a; i <= b; i++) #define fb(i,b,a) for(int i = b; i >= a; i--) #define trav(a,x) for(auto& a : x) #define sz(a) (int)(a).size() #define fi first #define se second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) const int mod = 1000000007; const int inf = 1e9 + 5; const int mxN = 250005; int n, X; int niz[mxN]; int pref[mxN]; const int L = 30; int idx = 0; int mx[20 * mxN]; int lipa[20 * mxN][2]; void add(int A, int pos){ int tr = 0; fb(i,L - 1,0){ int a = ((A >> i) & 1); if(!lipa[tr][a])lipa[tr][a] = ++idx; tr = lipa[tr][a]; mx[tr] = max(mx[tr], pos); } } int query(int A){ int tr = 0, ans = 0; fb(i,L - 1,0){ int a = ((A >> i) & 1); int b = ((X >> i) & 1); if(b == 1){ if(!lipa[tr][a ^ 1])return ans; tr = lipa[tr][a ^ 1]; } else{ if(lipa[tr][a ^ 1])ans = max(ans, mx[lipa[tr][a ^ 1]]); if(!lipa[tr][a])return ans; tr = lipa[tr][a]; } } return max(mx[tr], ans); } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> X; ff(i,1,n)cin >> niz[i]; ff(i,1,n)pref[i] = pref[i - 1] ^ niz[i]; int pos = 0, duz = 0; fb(i,n,1){ add(pref[i], i); int gde = query(pref[i - 1]); if(duz <= gde - i + 1){ duz = gde - i + 1; pos = i; } } cout << pos << " " << duz << '\n'; return 0; } /* 4 6 6 1 2 4 4 6 0 0 0 6 // probati bojenje sahovski */
#Verdict Execution timeMemoryGrader output
Fetching results...