# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
393081 |
2021-04-22T17:07:54 Z |
SavicS |
XOR (IZhO12_xor) |
C++14 |
|
128 ms |
37812 KB |
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 250005;
const int inf = 1e9 + 5;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
int n, X;
int niz[maxn];
int pref[maxn];
int idx = 0;
int najm[20 * maxn];
int lipa[20 * maxn][2];
void add(int A, int id) {
int tr = 0;
fb(mask,30,0) {
int bt = 0;
if(A & (1ll << mask))bt = 1;
if(lipa[tr][bt] == 0)lipa[tr][bt] = ++idx;
tr = lipa[tr][bt];
najm[tr] = min(najm[tr], id);
}
}
int kve(int A) {
int tr = 0;
int mn = inf;
bool ok = 1;
fb(mask,30,0) {
int btA = 0;
if(A & (1ll << mask))btA = 1;
int btX = 0;
if(X & (1ll << mask))btX = 1;
// cout << "btA: " << btA << endl;
// cout << "btX: " << btX << endl;
if(btA == 1) {
if(btX == 1) {
if(lipa[tr][0] == 0) {
ok = 0;
break;
}
tr = lipa[tr][0];
} else {
int ntr = lipa[tr][0];
if(ntr != 0) {
mn = min(mn, najm[ntr]);
}
if(lipa[tr][1] == 0) {
ok = 0;
break;
}
tr = lipa[tr][1];
}
} else {
if(btX == 0) {
int ntr = lipa[tr][1];
if(ntr != 0) {
mn = min(mn, najm[ntr]);
}
// cout << "ovde: " << endl;
if(lipa[tr][0] == 0) {
ok = 0;
break;
}
tr = lipa[tr][0];
} else {
if(lipa[tr][1] == 0) {
ok = 0;
break;
}
tr = lipa[tr][1];
}
}
// cout << "------------------" << endl;
// cout << endl;
}
if(ok)mn = min(mn, najm[tr]);
return mn;
}
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> n >> X;
ff(i,1,n)cin >> niz[i];
ff(i,1,n)pref[i] = pref[i - 1] ^ niz[i];
memset(najm, inf, sizeof(najm));
int rez = 0;
int poz = 0;
add(0, 0);
ff(i,1,n) {
// pref[i] ^ pref[j - 1] >= x
int pos = kve(pref[i]);
if(i - pos > rez) {
rez = i - pos;
poz = pos + 1;
}
add(pref[i], i);
}
cout << poz << " " << rez << endl;
return 0;
}
/**
2 6
6 1
// probati bojenje sahovski ili slicno
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19916 KB |
Output is correct |
2 |
Correct |
11 ms |
19848 KB |
Output is correct |
3 |
Correct |
10 ms |
19816 KB |
Output is correct |
4 |
Correct |
10 ms |
19916 KB |
Output is correct |
5 |
Correct |
16 ms |
20496 KB |
Output is correct |
6 |
Correct |
18 ms |
20644 KB |
Output is correct |
7 |
Correct |
18 ms |
20684 KB |
Output is correct |
8 |
Correct |
19 ms |
20756 KB |
Output is correct |
9 |
Correct |
46 ms |
27976 KB |
Output is correct |
10 |
Correct |
47 ms |
28012 KB |
Output is correct |
11 |
Correct |
49 ms |
27972 KB |
Output is correct |
12 |
Correct |
47 ms |
27972 KB |
Output is correct |
13 |
Correct |
50 ms |
28040 KB |
Output is correct |
14 |
Correct |
48 ms |
28076 KB |
Output is correct |
15 |
Correct |
48 ms |
28068 KB |
Output is correct |
16 |
Correct |
48 ms |
27984 KB |
Output is correct |
17 |
Correct |
125 ms |
37700 KB |
Output is correct |
18 |
Correct |
128 ms |
37812 KB |
Output is correct |
19 |
Correct |
124 ms |
37756 KB |
Output is correct |
20 |
Correct |
124 ms |
37796 KB |
Output is correct |