#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
const int NN = 1002;
int n, a[NN], calc[NN][NN];
void dnc(int L, int R){
if(L + 1 >= R) return;
int mid = L + R >> 1;
calc[mid][mid] = a[mid], calc[mid + 1][mid + 1] = a[mid + 1];
for(int i = mid - 1; i >= L; --i) calc[i][mid] = Secret(a[i], calc[i + 1][mid]);
for(int i = mid + 2; i <= R; ++i) calc[mid + 1][i] = Secret(calc[mid + 1][i - 1], a[i]);
dnc(L, mid); dnc(mid + 1, R);
}
void Init(int N, int A[]){
n = N;
for(int i = 1; i <= n; ++i) a[i] = A[i - 1];
memset(calc, 255, sizeof(calc)); dnc(1, n);
}
int Query(int L, int R){
++L; ++R;
if(L == R) return a[L];
if(L + 1 == R) return Secret(a[L], a[R]);
int i;
for(i = L; i < R; ++i) if(calc[L][i] != -1 && calc[i + 1][R] != -1) break;
return Secret(calc[L][i], calc[i + 1][R]);
}
Compilation message
secret.cpp: In function 'void dnc(int, int)':
secret.cpp:8:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
8 | int mid = L + R >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
6216 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 |
6236 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
125 ms |
6220 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
471 ms |
8140 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
439 ms |
8192 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
459 ms |
8280 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
448 ms |
8124 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
449 ms |
8116 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
442 ms |
8140 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
483 ms |
8204 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |