# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
784412 | chanhchuong123 | Secret (JOI14_secret) | C++14 | 398 ms | 8632 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 "secret.h"
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
const int MAX = 1000;
int n;
int a[MAX];
int mask[MAX];
int dp[10][MAX];
void divi(int l, int r, int lev) {
if (l == r) return;
int mid = l + r >> 1;
dp[lev][mid] = a[mid]; dp[lev][mid + 1] = a[mid + 1];
for (int i = mid - 1; i >= l; --i) dp[lev][i] = Secret(dp[lev][i + 1], a[i]);
for (int i = mid + 2; i <= r; ++i) dp[lev][i] = Secret(dp[lev][i - 1], a[i]);
for (int i = mid + 1; i <= r; ++i) mask[i] = 1 << lev;
divi(l, mid, lev + 1); divi(mid + 1, r, lev + 1);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; ++i) {
a[i] = A[i];
mask[i] = 0;
}
divi(0, n - 1, 0);
}
int Query(int L, int R) {
if (L == R) return a[L];
int lev = __builtin_ctz(mask[L] ^ mask[R]);
return Secret(dp[lev][L], dp[lev][R]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |