Submission #703007

#TimeUsernameProblemLanguageResultExecution timeMemory
703007NeroZeinSecret (JOI14_secret)C++17
100 / 100
419 ms8236 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; const int N = 1003; int n; vector<int> a; int st[N][N]; void solve (int l, int r) { if (l == r) { return; } int mid = (l + r) >> 1; solve(l, mid); solve(mid+1, r); st[mid][mid] = a[mid]; for (int i = mid - 1; i >= l; --i) { st[i][mid] = Secret(a[i], st[i+1][mid]); } st[mid+1][mid+1] = a[mid+1]; for (int i = mid+2; i <= r; ++i) { st[mid+1][i] = Secret(st[mid+1][i-1], a[i]); } } void Init(int N_, int A[]) { n = N_; a.resize(n); for (int i = 0; i < n; i++) a[i] = A[i]; solve(0, n - 1); } int get (int l, int r, int s, int e) { if (s == e) { return a[s]; } int mid = (l + r) >> 1; if (s > mid) { return get(mid+1, r, s, e); } if (e <= mid) { return get(l, mid, s, e); } return Secret(st[s][mid], st[mid+1][e]); } int Query(int L, int R) { return get(0, n-1, L, R); }
#Verdict Execution timeMemoryGrader output
Fetching results...