#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
int n, a[1003], tr[2003][1003];
void build(int x, int l, int r, int rig) {
if (l == r) {
tr[x][l] = a[l];
return;
}
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
build(x + 1, l, y, 0);
build(z, y + 1, r, 1);
if (rig == -1) {
return;
}
if (rig) {
tr[x][l] = a[l];
for (int i = l + 1; i <= r; i++) {
tr[x][i] = Secret(tr[x][i - 1], a[i]);
}
} else {
tr[x][r] = a[r];
for (int i = r - 1; i >= l; i--) {
tr[x][i] = Secret(a[i], tr[x][i + 1]);
}
}
}
int get(int x, int l, int r, int ll, int rr) {
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
if (rr <= y) {
return get(x + 1, l, y, ll, rr);
}
if (ll > y) {
return get(z, y + 1, r, ll, rr);
}
return Secret(tr[x + 1][ll], tr[z][rr]);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; i++) {
a[i] = A[i];
}
build(0, 0, n - 1, -1);
}
int Query(int l, int r) {
if (l == r) {
return a[l];
}
return get(0, 0, n - 1, l, r);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
6412 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
126 ms |
6588 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
126 ms |
6376 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
442 ms |
12180 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
446 ms |
12184 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
444 ms |
12196 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
442 ms |
12172 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
444 ms |
12192 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
458 ms |
12176 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
446 ms |
12208 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |