#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
int n, g[1005][1005];
void build(int l, int r){
if (r - l < 2) return;
int mid = l + r >> 1;
for (int i = mid - 1; i >= l; i--)
g[i][mid] = Secret(g[i][i], g[i + 1][mid]);
for (int i = mid + 2; i <= r; i++)
g[mid + 1][i] = Secret(g[mid + 1][i - 1], g[i][i]);
build(l, mid - 1), build(mid + 2, r);
}
void Init(int N, int A[]){
memset(g, -1, sizeof g);
n = N;
for (int i = 0; i < n; i++) g[i][i] = A[i];
build(0, n - 1);
}
int Query(int L, int R){
if (g[L][R] != -1) return g[L][R];
if (L + 1 == R) return Secret(g[L][L], g[R][R]);
for (int i = L; i < R; i++)
if (g[L][i] != -1 && g[i + 1][R] != -1) return Secret(g[L][i], g[i + 1][R]);
}
Compilation message
secret.cpp: In function 'void build(int, int)':
secret.cpp:7:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
secret.cpp: In function 'int Query(int, int)':
secret.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
6392 KB |
Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
149 ms |
6520 KB |
Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
164 ms |
6520 KB |
Output is correct - number of calls to Secret by Init = 3100, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
510 ms |
8436 KB |
Output is correct - number of calls to Secret by Init = 6988, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
515 ms |
8312 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
502 ms |
8396 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
518 ms |
8524 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
507 ms |
8312 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
529 ms |
8440 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
516 ms |
8312 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |