# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
589519 | TheEvilBird | XOR (IZhO12_xor) | C++17 | 1 ms | 212 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 <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <numeric>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <ctime>
#include <chrono>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128_t int128;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const char en = '\n';
const int INF = 1e9 + 7;
const ll INFLL = 1e18;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifdef __APPLE__
#include "debug.h"
//#define debug(...) 42
#else
#define debug(...) 42
#endif
const int N = 250'000;
const int LOG = 4;
int get_mask(int mask, int i) {
return ((mask & (1 << i)) > 0);
}
void solve() {
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<vector<int>> pref(LOG, vector<int> (n + 1, 0));
vector<vector<int>> precalc(LOG, vector<int> (n + 1, -1));
for (int l = 0; l < LOG; ++l) {
precalc[l][pref[l][0]] = 0;
for (int i = 0; i < n; ++i) {
pref[l][i + 1] = pref[l][i] + get_mask(a[i], l);
precalc[l][pref[l][i + 1]] = i + 1;
}
}
int ans = -1, idans = -1;
auto chkmx = [&](int cur, int i) {
if (cur > ans) {
ans = cur;
idans = i + 1;
}
};
for (int i = 0; i < n; ++i) {
int now = n - i;
for (int l = LOG - 1; l >= 0; --l) {
if (get_mask(x, l)) {
int cur_pref = pref[l][i + now] - pref[l][i];
if (cur_pref == 0) {
now = -1;
break;
}
if (cur_pref % 2 == 0) {
--cur_pref;
int pos = precalc[l][cur_pref];
now = min(now, pos - i);
}
}
else {
int cur = now;
int cur_pref = pref[l][i + now] - pref[l][i];
if (cur_pref == 0) {
cur = -1;
}
else if (cur_pref % 2 == 0) {
--cur_pref;
int pos = precalc[l][cur_pref];
cur = min(cur, pos - i);
}
chkmx(cur, i);
}
}
chkmx(now, i);
}
assert(ans != -1);
cout << idans << ' ' << ans << en;
}
int main() {
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |