# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
381652 | flappybird | Secret (JOI14_secret) | C++14 | 534 ms | 12304 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;
typedef int ll;
#define MAX 1010
struct range {
ll x, y;
ll v;
};
vector<range> vv;
vector<ll> a;
ll arr1[MAX][MAX];
ll arr2[MAX][MAX];
void init(ll low, ll high) {
if (low >= high) return;
ll mid = (low + high) / 2;
vv.push_back({ low, high, mid });
init(low, mid);
init(mid + 1, high);
}
void Init(int N, int A[]) {
init(1, N);
ll i, j;
ll mid;
a.resize(N + 1);
for (i = 0; i < N; i++) a[i + 1] = A[i];
for (i = 0; i < vv.size(); i++) {
mid = vv[i].v;
arr1[mid][mid] = A[mid - 1];
for (j = mid - 1; j >= vv[i].x; j--) arr1[mid][j] = Secret(A[j - 1], arr1[mid][j + 1]);
if (mid + 1 <= vv[i].y) arr2[mid][mid + 1] = A[mid];
for (j = mid + 2; j <= vv[i].y; j++) arr2[mid][j] = Secret(arr2[mid][j - 1], A[j - 1]);
}
}
int Query(int L, int R) {
ll i;
L++;
R++;
if (L == R) return a[L];
if (R - L == 1) return Secret(a[L], a[R]);
ll m = 0;
ll aa;
aa = 0;
for (i = 0; i < vv.size(); i++) {
if (vv[i].x <= L && R <= vv[i].y && L <= vv[i].v && vv[i].v <= R) {
if (m < vv[i].y - vv[i].x) {
m = vv[i].y - vv[i].x;
aa = i;
}
}
}
if (vv[aa].v == L) return Secret(a[L], arr2[vv[aa].v][R]);
if (vv[aa].v == R) return arr1[vv[aa].v][L];
return Secret(arr1[vv[aa].v][L], arr2[vv[aa].v][R]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |