#include <bits/stdc++.h>
#include "secret.h"
int memo[1000][1000], n;
void build(int l, int r, int A[]){
int m = (l + r) / 2;
memo[m][m] = A[m];
memo[m + 1][m + 1] = A[m + 1];
for(int i = m + 2; i <= r; i++) memo[m + 1][i] = Secret(memo[m + 1][i - 1], A[i]);
for(int i = m - 1; i >= l; i--) memo[m][i] = Secret(A[i], memo[m][i + 1]);
if(l < m) build(l, m, A);
if(m + 1 < r) build(m + 1, r, A);
}
void Init(int N, int A[]){
n = N;
build(0, n - 1, A);
}
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(memo[m][L], memo[m + 1][R]);
else if(m == R) return memo[m][L];
else if(m < L) l = m + 1;
else r = m;
}
return memo[l][l];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
6468 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
110 ms |
6232 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
114 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 |
394 ms |
8280 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
384 ms |
8276 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
392 ms |
8284 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
399 ms |
8216 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
389 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 |
385 ms |
8284 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
382 ms |
8280 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |