Submission #117533

#TimeUsernameProblemLanguageResultExecution timeMemory
117533tjd229Secret (JOI14_secret)C++14
0 / 100
20086 ms8428 KiB
#include "secret.h" int range[1000][1000]; int _A[1000], _N; void pre(int s, int e,int lev) { if (s >= e) return; int m = (s + e) >> 1; for (int i = m - 1; i >= s; --i) range[i][m] = Secret(_A[i],range[i+1][m]); pre(s, m - 1,lev+1); ++m; for (int i = m + 1; i <= e; ++i) range[m][i] = Secret(range[m][i - 1], _A[i]); --m; pre(m+1,e,lev+1); } void Init(int N, int A[]) { _N = N; for (int i = 0; i < N; ++i) _A[i] =range[i][i]= A[i]; pre(0, N - 1,0); } int op(int s,int e,int l,int r) { int m = (s+e)>>1; if (m <= r && m + 1 >= l) { if (r == m || m+1==l) return range[l][r]; return Secret(range[l][m],range[m+1][r]); } if (m > r) return op(m+2,e,l,r); else return op(s,m-1,l,r); } int Query(int L, int R) { if (L == R) return _A[L]; else if (L + 1 == R) return Secret(_A[L], _A[R]); return op(0,_N-1,L,R); }
#Verdict Execution timeMemoryGrader output
Fetching results...