Submission #984432

#TimeUsernameProblemLanguageResultExecution timeMemory
984432LOLOLOSecret (JOI14_secret)C++14
100 / 100
364 ms8524 KiB
//#include <bits/stdc++.h> #include "secret.h" using namespace std; const int N = 1e3 + 10; int n; int a[N], f[N][N]; void prepare(int l, int r) { if (l >= r) { f[l][l] = a[l]; return; } int m = (l + r) / 2; f[m][m] = a[m]; f[m + 1][m + 1] = a[m + 1]; for (int j = m + 2; j <= r; j++) { f[m + 1][j] = Secret(f[m + 1][j - 1], a[j]); } for (int j = m - 1; j >= l; j--) { f[j][m] = Secret(a[j], f[j + 1][m]); } prepare(l, m); prepare(m + 1, r); } void Init(int _n, int _a[]) { n = _n; for (int i = 0; i < n; i++) a[i] = _a[i]; prepare(0, n - 1); } int get(int l, int r, int u, int v) { int m = (l + r) / 2; if (m < u) return get(m + 1, r, u, v); if (m > v) return get(l, m, u, v); if (v == m) return f[u][v]; return Secret(f[u][m], f[m + 1][v]); } int Query(int l, int r) { if (l == r) { return a[l]; } return get(0, n - 1, l, r); }
#Verdict Execution timeMemoryGrader output
Fetching results...