# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
76376 | 2018-09-13T08:41:34 Z | MiricaMatei | Secret (JOI14_secret) | C++14 | 0 ms | 0 KB |
#include "secret.h" int v[1005][1005]; void solve(int l, int r) { if (l >= r) return ; int med = (l + r) / 2; solve(l, med); solve(med + 1, r); for (int i = med - 1; i >= l; --i) { assert(v[i][i] != -1 && v[i + 1][med] != -1); v[i][med] = Secret(v[i][i], v[i + 1][med]); } for (int i = med + 2; i <= r; ++i) { v[med + 1][i] = Secret(v[i][i], v[med + 1][i - 1]); } } void Init(int N, int A[]) { for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) v[i][j] = -1; for (int i = 0; i < N; ++i) v[i][i] = A[i]; solve(0, N - 1); } int Query(int L, int R) { if (L == R) return v[L][L]; if (R == L + 1) return Secret(v[L][L], v[R][R]); for (int k = L; k < R; ++k) if (v[L][k] != -1 && v[k + 1][R] != -1) return Secret(v[L][k], v[k + 1][R]); }