#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> nums;
int stored[1001][1001];
void dnc(int l, int r){
if (l == r) return;
if (r - l == 1){
if (stored[l][r] != -1) return;
stored[l][r] = Secret(nums[l], nums[r]);
return;
}
int mid = (l + r) / 2;
int accum = (stored[mid - 1][mid] == -1 ? Secret(nums[mid - 1], nums[mid]) : stored[mid - 1][mid]);
stored[mid - 1][mid] = accum;
for (int i = mid - 2; i >= l; i--){
if (stored[i][mid] != -1) accum = stored[i][mid];
else stored[i][mid] = accum = Secret(nums[i], accum);
}
mid++;
accum = (stored[mid][mid + 1] == -1 ? Secret(nums[mid], nums[mid + 1]) : stored[mid][mid + 1]);
stored[mid][mid + 1] = accum;
for (int i = mid + 2; i <= r; i++){
if (stored[mid][i] != -1) accum = stored[mid][i];
else stored[mid][i] = accum = Secret(accum, nums[i]);
}
mid--;
dnc(l, mid);
dnc(mid, r);
}
void Init(int N, int A[]) {
memset(stored, -1, sizeof stored);
for (int i = 0; i < N; i++){
nums.push_back(A[i]);
stored[i][i] = A[i];
}
dnc(0, N - 1);
}
int Query(int L, int R) {
if (L == R) return nums[L];
if (R - L == 1) return Secret(nums[L], nums[R]);
for (int i = L; i < R; i++){
if (stored[L][i] != -1 && stored[i + 1][R] != -1) return Secret(stored[L][i], stored[i + 1][R]);
}
return stored[L][R];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
6372 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
150 ms |
6372 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
148 ms |
6500 KB |
Output is correct - number of calls to Secret by Init = 3604, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
510 ms |
8440 KB |
Output is correct - number of calls to Secret by Init = 7954, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
512 ms |
8292 KB |
Output is correct - number of calls to Secret by Init = 7964, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
522 ms |
8200 KB |
Output is correct - number of calls to Secret by Init = 7964, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
562 ms |
8292 KB |
Output is correct - number of calls to Secret by Init = 7964, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
516 ms |
8420 KB |
Output is correct - number of calls to Secret by Init = 7964, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
519 ms |
8396 KB |
Output is correct - number of calls to Secret by Init = 7964, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
515 ms |
8420 KB |
Output is correct - number of calls to Secret by Init = 7964, maximum number of calls to Secret by Query = 1 |