# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
838602 | Chal1shkan | Secret (JOI14_secret) | C++14 | 412 ms | 4360 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 nl "\n"
const int maxn = 1e3 + 3;
int tl[10][maxn];
int tr[10][maxn];
int a[maxn], n, ans;
void doit (int l, int r, int d) {
if (l >= r) return;
// cout << "vot " << l << ' ' << r << ' ' << d << '\n';
int mid = (l + r) >> 1;
tl[d][mid] = a[mid];
for (int i = mid - 1; i >= l; --i) {
tl[d][i] = Secret(a[i], tl[d][i + 1]);
}
// cout << "tl side" << nl;
// for (int i = mid; i >= l; --i) {
// cout << tl[d][i] << ' ';
// }
// cout << nl;
tr[d][mid + 1] = a[mid + 1];
for (int i = mid + 2; i <= r; ++i) {
tr[d][i] = Secret(tr[d][i - 1], a[i]);
}
// cout << "tr side" << nl;
// for (int i = mid + 1; i <= r; ++i) {
// cout << tr[d][i] << ' ';
// }
// cout << nl;
doit(l, mid, d + 1);
doit(mid + 1, r, d + 1);
}
void solve (int L, int R, int l, int r, int d) {
if (l >= r) {
return;
}
int mid = (l + r) >> 1;
if (l <= L && L <= mid && mid + 1 <= R && R <= r) {
ans = Secret(tl[d][L], tr[d][R]);
return;
}
solve (L, R, l, mid, d + 1);
solve (L, R, mid + 1, r, d + 1);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < N; ++i) {
a[i] = A[i];
}
doit (0, n - 1, 1);
}
int Query(int L, int R) {
if (L == R) {
return a[L];
}
ans = 0;
solve (L, R, 0, n - 1, 1);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |