제출 #1029249

#제출 시각아이디문제언어결과실행 시간메모리
1029249TrinhKhanhDungXOR (IZhO12_xor)C++14
100 / 100
108 ms121680 KiB
#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; }

컴파일 시 표준 에러 (stderr) 메시지

xor.cpp: In function 'void solve()':
xor.cpp:95:20: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   95 |     cout << pos << ' ' << ans << '\n';
      |                    ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...