#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
int prefix[1001][1001], n;
vector<pair<int, int>> ranges;
void populate(int L, int R, int A[]){
int mid = (L + R) / 2;
prefix[mid][mid] = A[mid];
prefix[mid + 1][mid + 1] = A[mid + 1];
for (int i = mid + 2; i <= R; i++)
prefix[mid + 1][i] = Secret(prefix[mid + 1][i - 1], A[i]);
for (int i = mid - 1; i >= L; i--)
prefix[mid][i] = Secret(A[i], prefix[mid][i + 1]);
ranges.push_back({L, R});
if (L < mid) populate(L, mid, A);
if (mid + 1 < R) populate(mid + 1, R, A);
}
void Init(int N, int A[]) {
n = N;
populate(0, N-1, A);
}
int Query(int L, int R) {
// return 0;
if (L == R) return prefix[L][L];
for (auto range: ranges){
int mid = (range.first+range.second)/2;
if (L >= range.first && R <= range.second ){
if (mid == R) return prefix[mid][L];
if (L <= mid && R > mid){
return Secret(prefix[mid][L], prefix[mid+1][R]);
}
}
}
}
Compilation message (stderr)
secret.cpp: In function 'int Query(int, int)':
secret.cpp:47:1: warning: control reaches end of non-void function [-Wreturn-type]
47 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |