# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
483304 | Alexandruabcde | Secret (JOI14_secret) | C++14 | 464 ms | 8312 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;
typedef long long LL;
constexpr int NMAX = 1005;
int n;
int V[NMAX];
int ans[NMAX][NMAX];
void Precalculare (int Left, int Right) {
if (Left >= Right) return;
int mij = (Left + Right) / 2;
ans[mij][mij] = V[mij];
for (int i = mij-1; i >= Left; -- i )
ans[i][mij] = Secret(V[i], ans[i+1][mij]);
ans[mij+1][mij+1] = V[mij+1];
for (int i = mij+2; i <= Right; ++ i )
ans[mij+1][i] = Secret(ans[mij+1][i-1], V[i]);
Precalculare(Left, mij);
Precalculare(mij+1, Right);
}
void Init (int N, int A[]) {
n = N;
for (int i = 1; i <= N; ++ i )
V[i] = A[i-1];
Precalculare(1, N);
}
int Answer (int st, int dr, int qa, int qb) {
int mij = (st + dr) / 2;
if (qa <= mij && mij < qb)
return Secret(ans[qa][mij], ans[mij+1][qb]);
if (qb <= mij)
return Answer(st, mij, qa, qb);
return Answer(mij+1, dr, qa, qb);
}
int Query(int L, int R) {
if (L == R) return V[L+1];
return Answer(1, n, L+1, R+1);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |