#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> mid, v;
void dc(int l, int r, int a[]) {
if (l > r) return;
int m = l + r >> 1;
v[m][m] = a[m];
if (m < r) v[m + 1][m + 1] = a[m + 1];
for (int i = l; i <= m - 1; i++)
for (int j = m + 1; j <= r; j++)
mid[i][j] = m;
for (int i = m - 1; i >= l; i--)
v[i][m] = Secret(a[i], v[i + 1][m]);
for (int i = m + 2; i <= r; i++)
v[m + 1][i] = Secret(v[m + 1][i - 1], a[i]);
dc(l, m - 1, a);
dc(m + 1, r, a);
}
void Init(int n, int a[]) {
mid = v = vector<vector<int>> (n, vector<int> (n, -1));
dc(0, n - 1, a);
}
int Query(int l, int r) {
if (v[l][r] != -1) return v[l][r];
int m = mid[l][r];
return Secret(v[l][m], v[m + 1][r]);
}
Compilation message
secret.cpp: In function 'void dc(int, int, int*)':
secret.cpp:9:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
9 | int m = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
112 ms |
4448 KB |
Wrong Answer [1] |
2 |
Incorrect |
110 ms |
4348 KB |
Wrong Answer [1] |
3 |
Incorrect |
113 ms |
4364 KB |
Wrong Answer [1] |
4 |
Incorrect |
424 ms |
12116 KB |
Wrong Answer [1] |
5 |
Incorrect |
413 ms |
12168 KB |
Wrong Answer [1] |
6 |
Incorrect |
414 ms |
12108 KB |
Wrong Answer [1] |
7 |
Correct |
431 ms |
12108 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
421 ms |
12180 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
425 ms |
12100 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
415 ms |
12100 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |