Submission #565531

#TimeUsernameProblemLanguageResultExecution timeMemory
565531ac2huSecret (JOI14_secret)C++14
0 / 100
760 ms24512 KiB
#include "secret.h" #include<bits/stdc++.h> using namespace std; const int _N = 1e3 + 1; int RR[_N][_N];// right[i][j] = query(j, i) int LL[_N][_N]; // left[i][j] = query(i, j) vector<int> temp; int a[_N]; int n; void build(int l,int r){ if(l + 1 < r){ int mid = (l + r + 1)/2; assert(mid < r && l <= mid); temp.push_back(mid); RR[mid + 1][mid] = a[mid + 1]; for(int i = mid + 2;i<=r;i++){ RR[i][mid] = Secret(RR[i - 1][mid], a[i]); } LL[mid][mid] = a[mid]; for(int i = mid - 1;i>=0;i--){ LL[i][mid] = Secret(a[i], LL[i + 1][mid]); } build(l, mid); build(mid + 1, r); } } void Init(int N, int A[]) { for(int i = 0;i<N;i++) a[i] = A[i]; build(1, N - 1); } int Query(int L, int R) { if(L == R){ return a[L]; } else if(L + 1 == R) return Secret(a[L], a[R]); else{ for(auto e : temp){ if(L <= e && e < R)return Secret(LL[L][e], RR[R][e]); } assert(false); } }
#Verdict Execution timeMemoryGrader output
Fetching results...