#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( 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-1];
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 );
}
/*int main()
{
int n, x[N], q;
scanf("%d",&n);
for( int i = 0 ; i < n ; i++ ) scanf("%d",&x[i]);
Init( n, x );
scanf("%d",&q);
while( q-- ) {
int a, b;
scanf("%d %d",&a,&b);
printf("%d\n",Query( a, b ) );
}
}*/
Compilation message
secret.cpp: In function 'void solve(int, int, int)':
secret.cpp:11: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:27:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
137 ms |
2424 KB |
Wrong Answer: Query(222, 254) - expected : 34031541, actual : 22166791. |
2 |
Incorrect |
137 ms |
2456 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 306225408. |
3 |
Incorrect |
144 ms |
2552 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 629483540. |
4 |
Incorrect |
500 ms |
4344 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 34079308. |
5 |
Incorrect |
503 ms |
4600 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 542818560. |
6 |
Incorrect |
500 ms |
4472 KB |
Wrong Answer: Query(915, 915) - expected : 282904741, actual : 579799611. |
7 |
Incorrect |
512 ms |
4344 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 772352096. |
8 |
Incorrect |
502 ms |
4436 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 290455552. |
9 |
Incorrect |
498 ms |
4344 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 164632041. |
10 |
Incorrect |
508 ms |
4436 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 872638089. |