Submission #916431

#TimeUsernameProblemLanguageResultExecution timeMemory
916431Dec0DeddSecret (JOI14_secret)C++14
100 / 100
388 ms8564 KiB
#include <bits/stdc++.h> #include "secret.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; const int N = 1e3+10; int n, a[N], que[N][N]; void gen(int l, int r) { if (l == r) { que[l][l]=a[l]; return; } int m=(l+r)/2; gen(l, m), gen(m+1, r); que[m+1][m+1]=a[m+1]; for (int i=m+2; i<=r; ++i) que[m+1][i]=Secret(que[m+1][i-1], a[i]); que[m][m]=a[m]; for (int i=m-1; i>=l; --i) que[i][m]=Secret(a[i], que[i+1][m]); } void Init(int _n, int ax[]) { n=_n; for (int i=1; i<=n; ++i) a[i]=ax[i-1]; gen(1, n); } int ans(int l, int r, int ql, int qr) { if (l == r) return que[l][l]; int m=(l+r)/2; if (ql <= m && m+1 <= qr) return Secret(que[ql][m], que[m+1][qr]); if (qr <= m) return ans(l, m, ql, qr); return ans(m+1, r, ql, qr); } int Query(int ql, int qr) { return ans(1, n, ql+1, qr+1); }
#Verdict Execution timeMemoryGrader output
Fetching results...