#include "secret.h"
int n;
int a[5555];
int B[5555];
int f[10][5555];
void divi(int l = 1, int r = n, int rt = 0) {
if (l == r || l + 1 == r)
return;
int m = (l + r) / 2, i;
f[rt][m] = a[m];
f[rt][m + 1] = a[m + 1];
for (i = m - 1; i >= l; i--)
f[rt][i] = Secret(a[i], f[rt][i + 1]);
for (i = m + 2; i <= r; i++)
f[rt][i] = Secret(f[rt][i - 1], a[i]);
divi(l, m, rt + 1);
divi(m + 1, r, rt + 1);
}
void Init(int N, int A[]) {
int i;
n = N;
for (i = 0; i < N; i++)
B[i] = A[i];
for (int i = 1; i <= n; i++)
a[i] = A[i - 1];
divi();
}
int dS(int L, int R, int l = 1, int r = n, int rt = 0) {
int m = (l + r) / 2, i;
if (R <= m)
return dS(L, R, l, m, rt + 1);
if (L > m)
return dS(L, R, m + 1, r, rt + 1);
return rt;
}
int Query(int L, int R) {
if (L == R)
return B[L];
if (L + 1 == R)
return Secret(B[L], B[L + 1]);
L++, R++;
int rt = dS(L, R);
return Secret(f[rt][L], f[rt][R]);
}
Compilation message
secret.cpp: In function 'int dS(int, int, int, int, int)':
secret.cpp:29:23: warning: unused variable 'i' [-Wunused-variable]
29 | int m = (l + r) / 2, i;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
2380 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
131 ms |
2480 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
124 ms |
2396 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
460 ms |
4300 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
440 ms |
4408 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
464 ms |
4428 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
459 ms |
4264 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
450 ms |
4356 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
462 ms |
4224 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
460 ms |
4400 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |