# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1029249 | TrinhKhanhDung | XOR (IZhO12_xor) | C++14 | 108 ms | 121680 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1019972207)
using namespace std;
template<class T1, class T2>
bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2>
void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}
template<class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}
template<class T>
void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int lim = 1e7 + 10;
struct Node{
int childs[2];
int val;
Node(){
memset(childs, -1, sizeof childs);
val = INF;
}
} nodes[lim];
int timer;
const int MAX = 3e5 + 10;
int N, X;
int a[MAX], pre[MAX];
void addKey(int num, int id){
int cur = 0;
for(int i=30; i>=0; i--){
int bit = BIT(num, i);
if(nodes[cur].childs[bit] == -1){
nodes[cur].childs[bit] = ++timer;
}
cur = nodes[cur].childs[bit];
minimize(nodes[cur].val, id);
}
}
int getVal(int num){
int cur = 0, ans = INF, val = 0;
for(int i=30; i>=0; i--){
if(cur == -1) break;
int bit = BIT(num, i);
if(val + MASK(i) >= X){
if(nodes[cur].childs[!bit] != -1){
minimize(ans, nodes[nodes[cur].childs[!bit]].val);
}
cur = nodes[cur].childs[bit];
}
else{
cur = nodes[cur].childs[!bit];
val += MASK(i);
}
}
return ans;
}
void solve(){
cin >> N >> X;
for(int i=1; i<=N; i++){
cin >> a[i];
}
addKey(0, 0);
int ans = 0, pos;
for(int i=1; i<=N; i++){
pre[i] = pre[i - 1] ^ a[i];
int p = getVal(pre[i]);
if(maximize(ans, i - p)){
pos = p + 1;
}
addKey(pre[i], i);
}
cout << pos << ' ' << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("task.inp", "r", stdin);
// freopen("task.out", "w", stdout);
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |