제출 #52543

#제출 시각아이디문제언어결과실행 시간메모리
52543kriiiSecret (JOI14_secret)C++17
100 / 100
660 ms4696 KiB
#include "secret.h" int n, a[1010]; int u[10][1010]; void go(int d, int l, int r) { if (l == r) return; int m = (l + r) / 2; u[d][m] = a[m]; for (int i = m-1; i >= l; i--) { u[d][i] = Secret(a[i],u[d][i+1]); } u[d][m + 1] = a[m + 1]; for (int i = m + 2; i <= r; i++) { u[d][i] = Secret(u[d][i-1],a[i]); } go(d + 1, l, m); go(d + 1, m + 1, r); } void Init(int N, int A[]) { n = N; for (int i = 0; i < n; i++) a[i] = A[i]; go(0, 0, N - 1); } int go2(int d, int l, int r, int L, int R) { if (r < L || R < l) return 0; int m = (l + r) / 2; if (R == m) return u[d][L]; if (L == m + 1) return u[d][R]; if (L <= m && m + 1 <= R) return Secret(u[d][L], u[d][R]); int p = go2(d + 1, l, m, L, R); int q = go2(d + 1, m + 1, r, L, R); return p + q; } int Query(int L, int R) { if (L == R) return a[L]; return go2(0,0,n-1,L,R); }
#Verdict Execution timeMemoryGrader output
Fetching results...