Submission #548089

#TimeUsernameProblemLanguageResultExecution timeMemory
548089JomnoiSecret (JOI14_secret)C++17
100 / 100
531 ms8312 KiB
#include <bits/stdc++.h> #include "secret.h" using namespace std; const int MAX_N = 1e3 + 10; int n; int dp[MAX_N][MAX_N]; int a[MAX_N]; void solve(int l, int r) { if(l > r) { return; } if(l == r) { return void(dp[l][l] = a[l]); } int mid = (l + r) / 2; solve(l, mid); solve(mid + 1, r); for(int i = l; i <= mid; i++) { if(dp[i][r] == -1) { dp[i][r] = Secret(dp[i][mid], dp[mid + 1][r]); } } for(int i = mid + 1; i <= r; i++) { if(dp[l][i] == -1) { dp[l][i] = Secret(dp[l][mid], dp[mid + 1][i]); } } } void Init(int N, int A[]) { n = N; for(int i = 0; i < N; i++) { a[i] = A[i]; } for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { dp[i][j] = -1; } } solve(0, (N - 1) / 2); solve((N - 1) / 2 + 1, N - 1); } int Query(int L, int R) { int l = 0, r = n - 1, mid = (n - 1) / 2; if(L == R) { return a[L]; } while(l <= r) { mid = (l + r) / 2; if(L <= mid and mid < R) { return Secret(dp[L][mid], dp[mid + 1][R]); } if(mid >= R) { r = mid; } else { l = mid + 1; } } return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...