Submission #134318

#TimeUsernameProblemLanguageResultExecution timeMemory
134318someone_aaSecret (JOI14_secret)C++17
0 / 100
599 ms12720 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1100; int prefix[maxn][maxn]; int suffix[maxn][maxn]; int arr[maxn], n; void precompute(int l, int r) { if(l == r) prefix[l][l] = suffix[l][l] = arr[l]; else { int mid = (l + r) / 2; prefix[mid][mid] = suffix[mid][mid] = arr[mid]; for(int i=mid-1;i>=l;i--) { suffix[mid][i] = Secret(arr[i], suffix[mid][i+1]); } for(int i=mid+1;i<=r;i++) { prefix[mid][i] = Secret(prefix[mid][i-1], arr[i]); } precompute(l, mid); precompute(mid+1,r); } } void Init(int N, int A[]) { n = N; for(int i=0;i<n;i++) { arr[i] = A[i]; } precompute(0, n-1); } int solve(int ql, int qr, int li=0, int ri=n-1) { if(li == ri) return arr[li]; else { int mid = (li + ri) / 2; if(ql <= mid && qr > mid) { //cout<<ql<<", "<<qr<<" mid point: "<<mid<<"Here: ["<<li<<", "<<ri<<"]\n"; return Secret(suffix[mid][ql], prefix[mid][qr]); } else if(qr <= mid) { return solve(ql, qr, li, mid); } else { return solve(ql, qr, mid+1, ri); } } } int Query(int L, int R) { return solve(L, R); }
#Verdict Execution timeMemoryGrader output
Fetching results...