제출 #1266297

#제출 시각아이디문제언어결과실행 시간메모리
1266297PlayVoltzXOR (IZhO12_xor)C++20
100 / 100
108 ms108760 KiB
#include <cstdio> #include <stdio.h> #include <stdbool.h> #include <iostream> #include <map> #include <vector> #include <climits> #include <stack> #include <string> #include <queue> #include <algorithm> #include <set> #include <unordered_set> #include <unordered_map> #include <cmath> #include <cctype> #include <bitset> #include <iomanip> #include <cstring> #include <numeric> #include <cassert> using namespace std; #define int long long #define pii pair<int, int> #define mp make_pair #define pb push_back #define fi first #define se second int n, x, trie[10000000][2], mn[10000000], counter=0; void insert(int a, int id){ int node=0; for (int i=30; i>=0; --i){ int b=(a>>i)&1; if (!trie[node][b])trie[node][b]=++counter; node=trie[node][b]; mn[node]=min(mn[node], id); } } int query(int a){ int res=LLONG_MAX/2, node=0; for (int i=30; i>=0; --i){ int b=(a>>i)&1, b2=(x>>i)&1; if (b2)node=trie[node][!b]; else{ if (trie[node][!b])res=min(res, mn[trie[node][!b]]); node=trie[node][b]; } if (!node)return res; } if (node)res=min(res, mn[node]); return res; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>x; vector<int> psum(n+1, 0); for (int i=0; i<10000000; ++i)mn[i]=LLONG_MAX/2; for (int i=1; i<=n; ++i)cin>>psum[i], psum[i]^=psum[i-1]; insert(0, 0); int best=-1, k, id; for (int i=1; i<=n; ++i){ int res=query(psum[i]); if (i-res>best)best=i-res, id=res+1, k=i-res; insert(psum[i], i); } cout<<id<<" "<<k; }
#Verdict Execution timeMemoryGrader output
Fetching results...