Submission #99165

#TimeUsernameProblemLanguageResultExecution timeMemory
99165WLZ비밀 (JOI14_secret)C++17
100 / 100
588 ms8460 KiB
#include "secret.h"
#include <bits/stdc++.h>

using namespace std;

vector< vector<int> > a;

void build(int l, int r, int A[]) {
  if (r - l <= 1) {
    return;
  }
  int mid = (l + r) / 2;
  for (int i = mid - 1; i >= l; i--) {
    a[i][mid] = Secret(A[i], a[i + 1][mid]);
  }
  for (int i = mid + 2; i <= r; i++) {
    a[mid + 1][i] = Secret(a[mid + 1][i - 1], A[i]);
  }
  build(l, mid, A);
  build(mid + 1, r, A);
}

void Init(int N, int A[]) {
  a.assign(N, vector<int>(N, -1));
  for (int i = 0; i < N; i++) {
    a[i][i] = a[i][i] = A[i];
  }
  build(0, N - 1, A);
}

int Query(int L, int R) {
  if (L == R) {
    return a[L][R];
  }
  if (a[L][R] != -1) {
    return a[L][R];
  }
  for (int mid = L; mid < R; mid++) {
    if (a[L][mid] != -1 && a[mid + 1][R] != -1) {
      return Secret(a[L][mid], a[mid + 1][R]);
    }
  }
  return -1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...