#include "secret.h"
int N;
int A[1010], T[20][1010];
void dnc(int d, int s, int e){
if (s == e) return;
int m=s+e>>1;
T[d][m+1] = A[m+1];
for (int i=m+2; i<=e; i++) T[d][i] = Secret(T[d][i-1], A[i]);
T[d][m] = A[m];
for (int i=m-1; i>=s; i--) T[d][i] = Secret(A[i], T[d][i+1]);
dnc(d+1, s, m), dnc(d+1, m+1, e);
}
void Init(int _N, int P[]){
N = _N;
for (int i=0; i<N; i++) A[i] = P[i];
dnc(0, 0, N-1);
}
int qry(int d, int s, int e, int ts, int te){
int m=s+e>>1;
if (ts <= m && m < te) return Secret(T[d][ts], T[d][te]);
if (te <= m) return qry(d+1, s, m, ts, te);
return qry(d+1, m+1, e, ts, te);
}
int Query(int L, int R){
if (L == R) return A[L];
return qry(0, 0, N-1, L, R);
}
Compilation message
secret.cpp: In function 'void dnc(int, int, int)':
secret.cpp:8:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
8 | int m=s+e>>1;
| ~^~
secret.cpp: In function 'int qry(int, int, int, int, int)':
secret.cpp:23:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | int m=s+e>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
2372 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
144 ms |
2320 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
159 ms |
2448 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
524 ms |
4188 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
511 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 |
508 ms |
4416 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
506 ms |
4288 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
517 ms |
4388 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
526 ms |
4240 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 |
4196 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |