#include <bits/stdc++.h>
#include "secret.h"
const int N = 1e3 + 10;
int n, a[N], prer[10][N], prel[10][N];
void solve( int l, int r, int cnt ) {
if( cnt > 9 || l == r ) return ;
int mid = l + r >> 1;
prer[cnt][mid+1] = a[mid+1];
prel[cnt][mid] = a[mid];
for( int i = mid - 1 ; i >= l ; i-- ) prel[cnt][i] = Secret( a[i], prel[cnt][i+1] );
for( int i = mid + 2 ; i <= r ; i++ ) prer[cnt][i] = Secret( prer[cnt][i-1], a[i] );
solve( l, mid, cnt+1 ), solve( mid+1, r, cnt+1 );
}
void Init( int N_, int A[] ) {
n = N_;
for( int i = 0 ; i < n ; i++ ) a[i] = A[i];
solve( 0, n-1, 1 );
}
int cal( int ll, int rr, int l, int r, int cnt ) {
int mid = l + r >> 1;
if( ll <= mid && mid + 1 <= rr ) return Secret( prel[cnt][ll], prer[cnt][rr] );
else if( rr <= mid ) return cal( ll, rr, l, mid, cnt + 1 );
else return cal( ll, rr, mid + 1, r, cnt + 1 );
}
int Query( int L, int R ) {
if( L == R ) return a[L];
else if( L + 1 == R ) return Secret( a[L], a[R] );
return cal( L, R, 0, n-1, 1 );
}
Compilation message
secret.cpp: In function 'void solve(int, int, int)':
secret.cpp:10:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
secret.cpp: In function 'int cal(int, int, int, int, int)':
secret.cpp:26:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
2424 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
146 ms |
2464 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
146 ms |
2424 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
509 ms |
4472 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
503 ms |
4472 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
506 ms |
4452 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
512 ms |
4472 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
511 ms |
4344 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
512 ms |
4476 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
508 ms |
4448 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |