#include "secret.h"
#include<bits/stdc++.h>
using namespace std;
int n, a[1005], arr[1005][1005];
void calc(int l, int r) {
if (l == r) {
arr[l][l] = a[l];
return;
}
int m = (l+r)/2;
arr[m][m] = a[m];
arr[m+1][m+1] = a[m+1];
for (int i = m-1; i >= l; i--) {
arr[m][i] = Secret(a[i], arr[m][i+1]);
}
for (int i = m+2; i <= r; i++) {
arr[m+1][i] = Secret(arr[m+1][i-1], a[i]);
}
calc(l, m);
calc(m+1, r);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; i++) {
a[i] = A[i];
}
calc(0, n-1);
}
int Query(int L, int R) {
int l = 0, r = n-1;
while(l < r) {
int m = (l+r)/2;
if (L <= m && m < R) {
return Secret(arr[m][L], arr[m+1][R]);
} else if (R == m) {
return arr[m][L];
} else if (L == m+1) {
return arr[m+1][R];
} else if (R < m) {
r = m;
} else {
l = m+1;
}
}
return arr[l][l];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
6736 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
70 ms |
6760 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 |
6740 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
260 ms |
8276 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
259 ms |
8300 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
273 ms |
8272 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
258 ms |
8284 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
265 ms |
8276 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
260 ms |
8272 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
272 ms |
8284 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |