#include "secret.h"
#include <vector>
using namespace std;
int n;
vector<vector<int>> tree(4005);
void buildTree(int node, int l, int r, int a[]) {
tree[node].resize(n);
if (node % 2) {
tree[node][l] = a[l];
for (int i = l + 1; i <= r; i++) {
tree[node][i] = Secret(tree[node][i - 1], a[i]);
}
} else {
tree[node][r] = a[r];
for (int i = r - 1; i >= l; i--) {
tree[node][i] = Secret(a[i], tree[node][i + 1]);
}
}
if (l != r) {
int mid = (l + r) / 2;
buildTree(2 * node, l, mid, a);
buildTree(2 * node + 1, mid + 1, r, a);
}
}
int query(int node, int l, int r, int L, int R) {
if (l == r) return tree[node][l];
int mid = (l + r) / 2;
if (R <= mid) return query(2 * node, l, mid, L, R);
else if (L > mid) return query(2 * node + 1, mid + 1, r, L, R);
else return Secret(tree[2 * node][L], tree[2 * node + 1][R]);
}
void Init(int N, int A[]) {
n = N;
buildTree(2, 0, (n - 1) / 2, A);
buildTree(3, ((n - 1) / 2) + 1, n - 1, A);
}
int Query(int L, int R) {
return query(1, 0, n - 1, L, R);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
4496 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
101 ms |
4460 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
103 ms |
4548 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
357 ms |
12148 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
358 ms |
12148 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
361 ms |
12148 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
359 ms |
12164 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
363 ms |
12260 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
365 ms |
12132 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
361 ms |
12328 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |