# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
883634 |
2023-12-05T14:42:32 Z |
Requiem |
XOR (IZhO12_xor) |
C++17 |
|
2000 ms |
127280 KB |
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 2147483646
#define endl "\n"
#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 = 501;
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()};
int bitpre, bit, it, p, pw2;
void addnum(int x){
p = 1;
for(it=29;it>=0;it--){
bit = (x>>it)&1;
if (Trie[p].child[bit] == 0){
Trie[p].child[bit] = Trie.size();
Trie.pb(TrieNode());
}
p = Trie[p].child[bit];
}
}
inline bool check(int pre,int x){
p = 1;
for(it=29;it>=0;it--){
bitpre = (pre>>it)&1;
pw2 = (1LL<<it);
if (Trie[p].child[!bitpre]){
if (x >= pw2 * 2) return false;
x -= pw2;
if (x <= 0) return true;
p = Trie[p].child[!bitpre];
}
else{
p = Trie[p].child[bitpre];
}
}
return (x <= 0);
}
};
Trie TrieBlock[2003];
int starting[MAXN],ending[MAXN];
int maxlen, minpos,x;
void update(int node,int l,int r,int pos,int pre){
TrieBlock[node].addnum(pre);
if (l==r) return;
int mid = (l+r)>>1;
if (pos <= mid) update(node<<1,l,mid,pos,pre);
else update(node<<1|1,mid+1,r,pos,pre);
}
int getminblock(int node,int l,int r,int u,int v,int pre){
int mid = (l+r)>>1;
if (l>=u and r<=v){
if (l==r) return l;
if (TrieBlock[node<<1].check(pre,x)){
return getminblock(node<<1,l,mid,u,v,pre);
}
else if (TrieBlock[node<<1|1].check(pre,x)){
return getminblock(node<<1|1,mid+1,r,u,v,pre);
}
else return INF;
}
if (l>v or r<u) return INF;
int g1 = getminblock(node<<1,l,mid,u,v,pre);
if (g1 != INF) return g1;
else return getminblock(node<<1|1,mid+1,r,u,v,pre);
}
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;
}
for(int i=0;i<=2002;i++){
TrieBlock[i].addnum(0);
}
int MXBLOCK = (n-1) / block;
int minblock = 0, idblock;
for(int i=0;i<=n;i++){
idblock = i / block;
minblock = getminblock(1,0,MXBLOCK,0,idblock,prexor[i]);
if (minblock != INF){
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);
}
}
}
}
update(1,0,MXBLOCK,idblock,prexor[i]);
}
cout<<minpos<<' '<<maxlen<<endl;
}
Compilation message
xor.cpp:87:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
87 | main()
| ^~~~
xor.cpp: In function 'int main()':
xor.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen(TASKNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
xor.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen(TASKNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2908 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
85 ms |
9204 KB |
Output is correct |
6 |
Correct |
152 ms |
11108 KB |
Output is correct |
7 |
Correct |
172 ms |
11416 KB |
Output is correct |
8 |
Correct |
205 ms |
12732 KB |
Output is correct |
9 |
Correct |
1250 ms |
108136 KB |
Output is correct |
10 |
Correct |
1234 ms |
107088 KB |
Output is correct |
11 |
Correct |
1268 ms |
107064 KB |
Output is correct |
12 |
Correct |
1281 ms |
107596 KB |
Output is correct |
13 |
Correct |
1231 ms |
107948 KB |
Output is correct |
14 |
Correct |
1217 ms |
105828 KB |
Output is correct |
15 |
Correct |
1251 ms |
108488 KB |
Output is correct |
16 |
Correct |
1248 ms |
106020 KB |
Output is correct |
17 |
Execution timed out |
2064 ms |
127280 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |