# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338617 | Berted | Secret (JOI14_secret) | C++14 | 544 ms | 8428 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 <vector>
using namespace std;
int N, res[1001][1001], cnt = 0;
vector<int> A;
void build(int L, int R)
{
if (L < R)
{
int M = L + R >> 1;
build(L, M);
build(M + 1, R);
res[M][M] = A[M]; res[M + 1][M + 1] = A[M + 1];
for (int i = M - 1; i >= L; i--) {cnt++; res[i][M] = Secret(A[i], res[i + 1][M]);}
for (int i = M + 2; i <= R; i++) {cnt++; res[M + 1][i] = Secret(res[M + 1][i - 1], A[i]);}
//cerr << "B: " << L << " " << R << " " << cnt << "\n";
}
}
int qry(int L, int R, int l, int r)
{
if (l == r) {return A[l];}
else if (L < R)
{
int M = L + R >> 1;
if (r <= M) {return qry(L, M, l, r);}
else if (l > M) {return qry(M + 1, R, l, r);}
else
{
//cerr << "Q:" << L << " " << l << " " << R << " " << r << " " << M << " " << res[l][M] << " " << res[M + 1][r] << "\n";
return Secret(res[l][M], res[M + 1][r]);
}
}
}
void Init(int N, int A[])
{
::N = N;
for (int i = 0; i < N; i++) {::A.push_back(A[i]);}
build(0, N - 1);
}
int Query(int L, int R)
{
return qry(0, N - 1, L, R);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |