# 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 >= 0; i--) {
ans[i][mid] = Secret(a[i],ans[i + 1][mid]);
//if (i == 1 && mid == 3) cout<<ans[i][mid]<<endl;
//cout<<i<<" "<<mid<<" "<<ans[i + 1][mid]<<" "<<a[i]<<" "<<ans[i][mid]<<endl;
}
for (int i = mid + 2; i < n; i++) {
ans[mid + 1][i] = Secret(ans[mid + 1][i - 1], a[i]);
//if (mid + 1 == 4 && i == 7) cout<<ans[mid + 1][i]<<endl;
//cout<<mid<<" "<<i<<" "<<ans[mid][i]<<endl;
}
solve(le, mid);
solve(mid + 1, ri);
}
int getans(int le, int ri, int start, int end) {
int mid = (le + ri) / 2;
//cout<<le<<" "<<ri<<" "<<start<<" "<<endl;
if (le <= start && ri >= end) {
// cout<<le<<" "<<ri<<" "<<start<<endl;
if (end == mid) {
return ans[start][mid];
}
if (start == mid + 1) {
return ans[mid + 1][end];
}
if (mid >= start && mid <= end) {
//cout<<start<<" "<<mid<<" "<<mid + 1<<" "<<end;
// cout<<start<<" "<<mid<<" "<<mid + 1<<" "<<end<<endl;
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:49:1: warning: control reaches end of non-void function [-Wreturn-type]
49 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
342 ms |
4500 KB |
Output isn't correct - number of calls to Secret by Init = 259590, maximum number of calls to Secret by Query = 1 |
2 |
Partially correct |
349 ms |
4456 KB |
Output isn't correct - number of calls to Secret by Init = 260610, maximum number of calls to Secret by Query = 1 |
3 |
Partially correct |
344 ms |
4480 KB |
Output isn't correct - number of calls to Secret by Init = 261632, maximum number of calls to Secret by Query = 1 |
4 |
Partially correct |
1336 ms |
8220 KB |
Output isn't correct - number of calls to Secret by Init = 995006, maximum number of calls to Secret by Query = 1 |
5 |
Partially correct |
1292 ms |
8304 KB |
Output isn't correct - number of calls to Secret by Init = 997002, maximum number of calls to Secret by Query = 1 |
6 |
Partially correct |
1311 ms |
8364 KB |
Output isn't correct - number of calls to Secret by Init = 997002, maximum number of calls to Secret by Query = 1 |
7 |
Partially correct |
1297 ms |
8388 KB |
Output isn't correct - number of calls to Secret by Init = 997002, maximum number of calls to Secret by Query = 1 |
8 |
Partially correct |
1284 ms |
8292 KB |
Output isn't correct - number of calls to Secret by Init = 997002, maximum number of calls to Secret by Query = 1 |
9 |
Partially correct |
1278 ms |
8216 KB |
Output isn't correct - number of calls to Secret by Init = 997002, maximum number of calls to Secret by Query = 1 |
10 |
Partially correct |
1275 ms |
8288 KB |
Output isn't correct - number of calls to Secret by Init = 997002, maximum number of calls to Secret by Query = 1 |