#include "secret.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int n;
int s[4 * maxn][maxn];
int a[maxn];
void Build(int x , int l , int r){
int mid = l + r >> 1;
s[x][mid] = a[mid];
for(int i = mid + 1 ; i <= r ; ++i){
s[x][i] = Secret(s[x][i - 1] , a[i]);
}
s[x][mid - 1] = a[mid - 1];
// if(mid == 6)cout << s[6][]
for(int i = mid - 2 ; i >= l ; --i){
s[x][i] = Secret(a[i] , s[x][i + 1]);
}
if(l == r){
return ;
}
Build(x * 2 , l , mid);
Build(x * 2 + 1 , mid + 1 , r);
}
void Init(int N, int A[]) {
n = N;
for(int i = n ; i >= 1 ; --i){
a[i] = A[i - 1];
}
Build(1 , 1 , n);
}
int query(int x , int l , int r , int L , int R){
int mid = l + r >> 1;
if(l > R || L > r)return -1;
if(L <= mid && mid <= R){
// cout << mid << " " << " " << l << " " << r << " " << s[x][R] << endl;
if(L == mid){
return s[x][R];
}
return Secret(s[x][L],s[x][R]);
}
int lef = query(x * 2 , l , mid , L , R);
if(lef != -1)return lef;
return query(x * 2 + 1 , mid + 1 , r , L , R);
}
int Query(int L, int R) {
++L;++R;
int res = query(1 , 1 , n , L , R);
if(res == -1)assert(0);
return res;
}
Compilation message
secret.cpp: In function 'void Build(int, int, int)':
secret.cpp:11:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
secret.cpp: In function 'int query(int, int, int, int, int)':
secret.cpp:37:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
6472 KB |
Output is correct - number of calls to Secret by Init = 3833, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
185 ms |
6392 KB |
Output is correct - number of calls to Secret by Init = 3842, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
183 ms |
6504 KB |
Output is correct - number of calls to Secret by Init = 3851, maximum number of calls to Secret by Query = 1 |
4 |
Partially correct |
606 ms |
12168 KB |
Output isn't correct - number of calls to Secret by Init = 8456, maximum number of calls to Secret by Query = 1 |
5 |
Partially correct |
607 ms |
12252 KB |
Output isn't correct - number of calls to Secret by Init = 8466, maximum number of calls to Secret by Query = 1 |
6 |
Partially correct |
609 ms |
12168 KB |
Output isn't correct - number of calls to Secret by Init = 8466, maximum number of calls to Secret by Query = 1 |
7 |
Partially correct |
615 ms |
12188 KB |
Output isn't correct - number of calls to Secret by Init = 8466, maximum number of calls to Secret by Query = 1 |
8 |
Partially correct |
610 ms |
12208 KB |
Output isn't correct - number of calls to Secret by Init = 8466, maximum number of calls to Secret by Query = 1 |
9 |
Partially correct |
608 ms |
12268 KB |
Output isn't correct - number of calls to Secret by Init = 8466, maximum number of calls to Secret by Query = 1 |
10 |
Partially correct |
609 ms |
12408 KB |
Output isn't correct - number of calls to Secret by Init = 8466, maximum number of calls to Secret by Query = 1 |