#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
const int kN = 1e3;
const int kLog = 11;
int n, a[kN], dp[kN][kLog];
void solve(int l, int r, int level) {
if (l == r) {
return;
}
int mid = (l + r) / 2;
dp[mid][level] = a[mid];
dp[mid + 1][level] = a[mid + 1];
for (int i = mid - 1; i >= l; --i) {
dp[i][level] = Secret(a[i], dp[i + 1][level]);
}
for (int i = mid + 2; i <= r; ++i) {
dp[i][level] = Secret(dp[i - 1][level], a[i]);
}
solve(l, mid, level + 1);
solve(mid + 1, r, level + 1);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; ++i) {
a[i] = A[i];
}
solve(0, n - 1, 0);
}
int Query(int l, int r) {
if (l == r) {
return a[l];
}
int st = 0, dr = n - 1, level = 0;
while (st <= dr) {
int mid = (st + dr) / 2;
if (l <= mid && mid < r) {
return Secret(dp[l][level], dp[r][level]);
}
if (mid < l) {
st = mid + 1;
} else {
dr = mid;
}
level += 1;
}
}
Compilation message
secret.cpp: In function 'int Query(int, int)':
secret.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
52 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
2356 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
129 ms |
2444 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
131 ms |
2340 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
490 ms |
4276 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
448 ms |
4292 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
482 ms |
4228 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
480 ms |
4372 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
458 ms |
4276 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
509 ms |
4256 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
454 ms |
4228 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |