Submission #636538

#TimeUsernameProblemLanguageResultExecution timeMemory
636538JooDdaeSecret (JOI14_secret)C++17
100 / 100
424 ms4556 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; #define mid ((l+r) >> 1) int n, a[1010]; vector<int> LL[4040], RR[4040]; void build(int node = 1, int l = 1, int r = n) { if(l > r) return; LL[node].push_back(a[mid]); for(int i=mid-1;i>=l;i--) { LL[node].push_back(Secret(a[i], LL[node].back())); } if(l == r) return; RR[node].push_back(a[mid+1]); for(int i=mid+2;i<=r;i++) { RR[node].push_back(Secret(RR[node].back(), a[i])); } build(node*2, l, mid-1), build(node*2+1, mid+1, r); } void Init(int N, int A[]) { n = N; for(int i=1;i<=n;i++) a[i] = A[i-1]; build(); } int find(int nl, int nr, int node = 1, int l = 1, int r = n) { if(nl <= mid && mid <= nr) { if(mid == nr) return LL[node][mid-nl]; return Secret(LL[node][mid-nl], RR[node][nr-mid-1]); } if(nr < mid) return find(nl, nr, node*2, l, mid-1); return find(nl, nr, node*2+1, mid+1, r); } int Query(int L, int R) { return find(L+1, R+1); }
#Verdict Execution timeMemoryGrader output
Fetching results...