# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
35970 | minhtung0404 | Secret (JOI14_secret) | C++14 | 669 ms | 9956 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "secret.h"
const int N = 1005;
using namespace std;
int n, a[N], f[N][N];
void cal(int l, int r){
int mid = (l + r) / 2;
f[mid][mid] = a[mid];
f[mid+1][mid+1] = a[mid+1];
if (r - l <= 1) return;
for (int i = mid-1; i >= l; i--) f[mid][i] = Secret(a[i], f[mid][i+1]);
for (int i = mid+2; i <= r; i++) f[mid+1][i] = Secret(f[mid+1][i-1], a[i]);
cal(l, mid); cal(mid+1, r);
}
int solve(int l, int r, int L, int R){
if (l == r) return a[l];
int mid = (l + r) / 2;
if (R <= mid) return solve(l, mid, L, R);
if (L >= mid+1) return solve(mid+1, r, L, R);
return Secret(f[mid][L], f[mid+1][R]);
}
void Init(int x, int y[]){
n = x; for (int i = 0; i < n; i++) a[i] = y[i];
cal(0, n-1);
}
int Query(int L, int R){
return solve(0, n-1, L, R);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |