#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
const int maxlvl = 15;
int n;
int rt[maxlvl][maxn], lf[maxlvl][maxn];
void create(int lvl, int l, int r, int A[]) {
if (l == r) {
lf[lvl][l] = A[l];
return;
}
int m = (l + r) >> 1;
// left side
lf[lvl][m] = A[m];
for (int i = m - 1; i >= l; i--) lf[lvl][i] = Secret(A[i], lf[lvl][i + 1]);
// right side
rt[lvl][m + 1] = A[m + 1];
for (int i = m + 2; i <= r; i++) rt[lvl][i] = Secret(rt[lvl][i - 1], A[i]);
create(lvl + 1, l, m, A);
create(lvl + 1, m + 1, r, A);
}
int get(int lvl, int l, int r, int L, int R) {
if (l == r) return lf[lvl][L];
int m = (l + r) >> 1;
if (R <= m) return get(lvl + 1, l, m, L, R);
if (L >= m+1) return get(lvl + 1, m+1, r, L, R);
return Secret(lf[lvl][L], rt[lvl][R]);
}
void Init(int N, int A[]) {
n = N;
create(0, 0, n - 1, A);
}
int Query(int L, int R) {
return get(0, 0, n - 1, L, R);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
2740 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
71 ms |
2740 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
71 ms |
2652 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
278 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
265 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
263 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
271 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
259 ms |
4268 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
273 ms |
4272 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
264 ms |
4268 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |