# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
961042 | Pring | Secret (JOI14_secret) | C++17 | 458 ms | 5012 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>
#include "secret.h"
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
namespace {
const int MXN = 1005;
int n, a[MXN], d[MXN];
map<pii, int> M;
struct SMG {
pii val[MXN * 2];
void build() {
FOR(i, 0, n) val[i + n] = mp(d[i], i);
for (int i = n - 1; i; i--) {
val[i] = min(val[i << 1], val[(i << 1) | 1]);
}
}
pii query(int l, int r) {
pii x = mp(INT_MAX, -1);
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) x = min(x, val[l++]);
if (r & 1) x = min(x, val[--r]);
}
return x;
}
} smg;
void SUF(int l, int r) {
int x = a[r - 1];
for (int i = r - 2; i >= l; i--) {
x = Secret(a[i], x);
M[mp(i, r - 1)] = x;
}
}
void PRE(int l, int r) {
int x = a[l];
for (int i = l + 1; i < r; i++) {
x = Secret(x, a[i]);
M[mp(l, i)] = x;
}
}
void build(int l, int r, int dep) {
if (l + 1 == r) return;
int mid = (l + r) >> 1;
d[mid] = dep;
SUF(l, mid);
PRE(mid, r);
build(l, mid, dep + 1);
build(mid, r, dep + 1);
}
void init() {
FOR(i, 0, n) M[mp(i, i)] = a[i];
build(0, n, 0);
smg.build();
}
int query(int l, int r) {
if (l == r) return a[l];
int bnd = smg.query(l + 1, r + 1).sc;
debug(bnd);
return Secret(M[mp(l, bnd - 1)], M[mp(bnd, r)]);
}
}
void Init(int N, int A[]) {
::n = N;
FOR(i, 0, n) a[i] = A[i];
init();
}
int Query(int l, int r) {
return query(l, r);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |