# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
269306 | ruler | Secret (JOI14_secret) | C++14 | 556 ms | 8452 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;
const int MAXN = 1e3 + 5;
int n, A[MAXN], DP[MAXN][MAXN];
void Build(int s = 0, int e = n) {
if (e - s < 2) {
DP[s][e] = A[s];
return;
}
int md = (s + e) >> 1;
Build(s, md), Build(md, e);
DP[md - 1][md] = A[md - 1];
for (int i = md - 2; i >= s; i--) DP[i][md] = Secret(A[i], DP[i + 1][md]);
DP[md][md + 1] = A[md];
for (int i = md + 2; i <= e; i++) DP[md][i] = Secret(DP[md][i - 1], A[i - 1]);
}
int Get(int l, int r, int s = 0, int e = n) {
int md = (s + e) >> 1;
if (r < md) return Get(l, r, s, md);
if (l > md) return Get(l, r, md, e);
return Secret(DP[l][md], DP[md][r]);
}
void Init(int _n, int _A[]) {
n = _n;
for (int i = 0; i < n; i++) A[i] = _A[i];
Build();
}
int Query(int l, int r) {
return Get(l, r + 1);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |