# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
393081 | SavicS | XOR (IZhO12_xor) | C++14 | 128 ms | 37812 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|---|---|---|---|
Fetching results... |