Submission #838713

#TimeUsernameProblemLanguageResultExecution timeMemory
838713adaawfSecret (JOI14_secret)C++14
100 / 100
411 ms4460 KiB
#include "secret.h" #include <iostream> using namespace std; int f[11][1005], g[11][1005], a[1005], n, res; void dnc(int l, int r, int x) { if (l >= r) return; int mid = (l + r) / 2; f[x][mid] = a[mid]; for (int i = mid - 1; i >= l; i--) { f[x][i] = Secret(a[i], f[x][i + 1]); } g[x][mid + 1] = a[mid + 1]; for (int i = mid + 2; i <= r; i++) { g[x][i] = Secret(g[x][i - 1], a[i]); } dnc(l, mid, x + 1); dnc(mid + 1, r, x + 1); } void trya(int tl, int tr, int l, int r, int x) { if (l >= r) { return; } int mid = (l + r) / 2; if (l <= tl && tl <= mid && mid + 1 <= tr && tr <= r) { res = Secret(f[x][tl], g[x][tr]); return; } trya(tl, tr, l, mid, x + 1); trya(tl, tr, mid + 1, r, x + 1); } void Init(int N, int A[]) { n = N; for (int i = 0; i < n; i++) { a[i] = A[i]; } dnc(0, n - 1, 1); } int Query(int L, int R) { if (L == R) { return a[L]; } res = 0; trya(L, R, 0, n - 1, 1); return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...