Submission #573935

#TimeUsernameProblemLanguageResultExecution timeMemory
573935VanillaSecret (JOI14_secret)C++17
0 / 100
466 ms24408 KiB
#include <bits/stdc++.h> #include "secret.h" using namespace std; const int maxn = 1001; int pref [maxn][maxn]; int sg [maxn][maxn]; void build (int l, int r) { if (l >= r) return; int mid = (l + r) / 2; for (int i = mid - 1; i >= l; i--){ for (int j = mid + 1; j <= r; j++){ sg[i][j] = mid; } } for (int i = mid + 2; i <= r; i++){ pref[mid + 1][i] = Secret(pref[mid + 1][i-1], pref[i][i]); } for (int i = mid - 1; i >= l; i--){ pref[i][mid] = Secret(pref[i + 1][mid], pref[i][i]); } build (l, mid); build (mid + 1, r); } void Init(int N, int A[]) { for (int i = 0; i < N; i++){ pref[i][i] = A[i]; } build(0, N - 1); // for (int i = 0; i < N; i++){ // for (int j = i; j < N; j++){ // cout << i << " " << j << " " << sg[i][j] << "\n"; // } // } } int Query(int L, int R) { if (pref[L][R]) return pref[L][R]; int mid = sg[L][R]; assert (pref[L][mid] && pref[mid + 1][R]); return Secret(pref[L][mid], pref[mid + 1][R]); }
#Verdict Execution timeMemoryGrader output
Fetching results...