# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883615 | Requiem | XOR (IZhO12_xor) | C++17 | 2013 ms | 22024 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 int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME "Xor"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 250009;
const int block = 500;
int n,k;
int a[MAXN],prexor[MAXN];
struct TrieNode{
int child[2];
TrieNode(){
memset(child,0,sizeof(child));
}
};
struct Trie{
vector<TrieNode> Trie = {TrieNode(),TrieNode()};
void addnum(int x){
int p = 1;
for(int i=30;i>=0;i--){
int bit = (x>>i)&1;
if (Trie[p].child[bit] == 0){
Trie[p].child[bit] = Trie.size();
Trie.pb(TrieNode());
}
p = Trie[p].child[bit];
}
}
bool check(int pre,int x){
int p = 1, mx = 0;
for(int i=30;i>=0;i--){
int bitpre = (pre>>i)&1;
int pw2 = (1LL<<i);
if (Trie[p].child[!bitpre]){
mx = mx + pw2;
if (mx >= x) return true;
p = Trie[p].child[!bitpre];
}
else{
p = Trie[p].child[bitpre];
}
}
return false;
}
};
Trie TrieBlock[503];
int starting[MAXN],ending[MAXN];
int maxlen, minpos,x;
main()
{
fast;
if (fopen(TASKNAME".inp","r")){
freopen(TASKNAME".inp","r",stdin);
freopen(TASKNAME".out","w",stdout);
}
cin>>n>>x;
for(int i=1;i<=n;i++){
cin>>a[i];
prexor[i] = prexor[i-1] ^ a[i];
}
for(int i=0;i<n;i++){
starting[i/block] = (starting[i/block] == -1) ? i : starting[i/block];
ending[i/block] = i;
}
int minblock = 0, idblock;
for(int i=0;i<=n;i++){
idblock = i / block;
minblock = idblock;
for(int b=0;b<idblock;b++){
if (TrieBlock[b].check(prexor[i],x)){
minblock = b;
break;
}
}
if (minblock != idblock){
for(int j=starting[minblock];j<=ending[minblock];j++){
if ((prexor[i] ^ prexor[j]) >= x) {
if (maximize(maxlen,i - j)){
minpos = j + 1;
}
else if (maxlen == i - j){
minimize(minpos, j + 1);
}
}
}
}
else{
for(int j=starting[idblock];j<i;j++){
// cout<<i<<' '<<j<<' '<<(prexor[i] ^ prexor[j])<<
// endl;
if ((prexor[i] ^ prexor[j]) >= x){
if (maximize(maxlen,i - j)){
minpos = j + 1;
}
else if (maxlen == i - j){
minimize(minpos, j + 1);
}
}
}
}
TrieBlock[idblock].addnum(prexor[i]);
}
cout<<minpos<<' '<<maxlen<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |