Submission #1043773

#TimeUsernameProblemLanguageResultExecution timeMemory
1043773TofuSecret (JOI14_secret)C++11
0 / 100
278 ms4436 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 1005; int n; int a[MAXN]; int ans[20][MAXN]; void F(int lv, int l, int r) { if(l == r) { ans[lv][l] = a[l]; return; } int m = (l + r) / 2; ans[lv][m] = a[m]; for(int i = m-1; i >= l; i--) { ans[lv][i] = Secret(a[i], ans[lv][i+1]); } ans[lv][m+1] = a[m+1]; for(int i = m+2; i <= r; i++) { ans[lv][i] = Secret(ans[lv][i-1], a[i]); } F(lv+1, l, m); F(lv+1, m+1, r); } int G(int lv, int l, int r, int ql, int qr) { int m = (l+r)/2; if(qr <= m) { return G(lv+1, l, m, ql, qr); } if(m+1 <= ql) { return G(lv+1, m+1, r, ql, qr); } return Secret(ans[lv][ql], ans[lv][qr]); } void Init(int N, int A[]) { n = N; for(int i = 1; i <= n; i++) a[i] = A[i-1]; F(1, 1, n); } int Query(int L, int R) { if(L == R) return a[L]; return G(1, 1, n, L, R); }
#Verdict Execution timeMemoryGrader output
Fetching results...