#include "secret.h"
#include <vector>
using namespace std;
int N, res[1001][1001], cnt = 0;
vector<int> A;
void build(int L, int R)
{
if (L < R)
{
int M = L + R >> 1;
build(L, M);
build(M + 1, R);
res[M][M] = A[M]; res[M + 1][M + 1] = A[M + 1];
for (int i = M - 1; i >= L; i--) {cnt++; res[i][M] = Secret(A[i], res[i + 1][M]);}
for (int i = M + 2; i <= R; i++) {cnt++; res[M + 1][i] = Secret(res[M + 1][i - 1], A[i]);}
//cerr << "B: " << L << " " << R << " " << cnt << "\n";
}
}
int qry(int L, int R, int l, int r)
{
if (l == r) {return A[l];}
else if (L < R)
{
int M = L + R >> 1;
if (r <= M) {return qry(L, M, l, r);}
else if (l > M) {return qry(M + 1, R, l, r);}
else
{
//cerr << "Q:" << L << " " << l << " " << R << " " << r << " " << M << " " << res[l][M] << " " << res[M + 1][r] << "\n";
return Secret(res[l][M], res[M + 1][r]);
}
}
}
void Init(int N, int A[])
{
::N = N;
for (int i = 0; i < N; i++) {::A.push_back(A[i]);}
build(0, N - 1);
}
int Query(int L, int R)
{
return qry(0, N - 1, L, R);
}
Compilation message
secret.cpp: In function 'void build(int, int)':
secret.cpp:13:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
13 | int M = L + R >> 1;
| ~~^~~
secret.cpp: In function 'int qry(int, int, int, int)':
secret.cpp:28:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int M = L + R >> 1;
| ~~^~~
secret.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
38 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
4460 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
146 ms |
4388 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
146 ms |
4716 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
513 ms |
8204 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
544 ms |
8428 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
530 ms |
8172 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
510 ms |
8172 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
512 ms |
8388 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
536 ms |
8208 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
512 ms |
8300 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |