# include <bits/stdc++.h>
# include <secret.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int M = 1005;
int a[M],ans[M][M],n;
/*int Secret(int a, int b) {
return min(1000000000, a + 2*(b/2));
}*/
void solve(int le, int ri) {
if (le == ri) return ;
int mid = (le + ri) / 2;
// cout<<le<<" "<<ri<<endl;
for (int i = mid - 1; i >= le; i--) {
ans[i][mid] = Secret(a[i],ans[i + 1][mid]);
}
for (int i = mid + 2; i <= ri; i++) {
ans[mid + 1][i] = Secret(ans[mid + 1][i - 1], a[i]);
}
solve(le, mid);
solve(mid + 1, ri);
}
int getans(int le, int ri, int start, int end) {
int mid = (le + ri) / 2;
if (le <= start && ri >= end) {
if (end == mid) {
return ans[start][mid];
}
if (start == mid + 1) {
return ans[mid + 1][end];
}
if (mid >= start && mid <= end) {
return Secret(ans[start][mid], ans[mid + 1][end]);
}
if (mid >= end) {
return getans(le,mid,start,end);
} else return getans(mid + 1, ri, start,end);
}
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; i++) {
a[i] = A[i];
ans[i][i] = a[i];
}
solve(0,n - 1);
}
int Query(int L,int R) {
return getans(0,n-1,L,R);
}
Compilation message
secret.cpp: In function 'int getans(int, int, int, int)':
secret.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
41 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
4316 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
122 ms |
4340 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
128 ms |
4304 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
436 ms |
8112 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
436 ms |
8220 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
435 ms |
8208 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
438 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 |
428 ms |
8164 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
443 ms |
8192 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
434 ms |
8156 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |