Submission #35970

#TimeUsernameProblemLanguageResultExecution timeMemory
35970minhtung0404Secret (JOI14_secret)C++14
100 / 100
669 ms9956 KiB
#include <bits/stdc++.h> #include "secret.h" const int N = 1005; using namespace std; int n, a[N], f[N][N]; void cal(int l, int r){ int mid = (l + r) / 2; f[mid][mid] = a[mid]; f[mid+1][mid+1] = a[mid+1]; if (r - l <= 1) return; for (int i = mid-1; i >= l; i--) f[mid][i] = Secret(a[i], f[mid][i+1]); for (int i = mid+2; i <= r; i++) f[mid+1][i] = Secret(f[mid+1][i-1], a[i]); cal(l, mid); cal(mid+1, r); } int solve(int l, int r, int L, int R){ if (l == r) return a[l]; int mid = (l + r) / 2; if (R <= mid) return solve(l, mid, L, R); if (L >= mid+1) return solve(mid+1, r, L, R); return Secret(f[mid][L], f[mid+1][R]); } void Init(int x, int y[]){ n = x; for (int i = 0; i < n; i++) a[i] = y[i]; cal(0, n-1); } int Query(int L, int R){ return solve(0, n-1, L, R); }
#Verdict Execution timeMemoryGrader output
Fetching results...