Submission #1135967

#TimeUsernameProblemLanguageResultExecution timeMemory
1135967huutuanSecret (JOI14_secret)C++20
100 / 100
339 ms8348 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; const int N=1010; int val[N][N], n, a[N]; void Init(int _n, int _a[]) { n=_n; for (int i=0; i<n; ++i) a[i]=_a[i]; auto dnc=[&](auto &&self, int l, int r) -> void { if (l>=r) return; int mid=(l+r)>>1; val[mid][mid]=a[mid]; for (int i=mid-1; i>=l; --i){ val[i][mid]=Secret(a[i], val[i+1][mid]); } if (mid+1<=r){ val[mid+1][mid+1]=a[mid+1]; for (int i=mid+2; i<=r; ++i){ val[mid+1][i]=Secret(val[mid+1][i-1], a[i]); } } self(self, l, mid-1); self(self, mid+2, r); }; dnc(dnc, 0, n-1); } int Query(int L, int R) { if (L==R) return a[L]; auto dnc=[&](auto &&self, int l, int r) -> int { if (l>=r) assert(false); int mid=(l+r)>>1; if (L<=mid && mid+1<=R){ return Secret(val[L][mid], val[mid+1][R]); } if (L==mid+1 || mid==R) return val[L][R]; if (R<mid) return self(self, l, mid-1); return self(self, mid+2, r); }; return dnc(dnc, 0, n-1); }
#Verdict Execution timeMemoryGrader output
Fetching results...