#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){
if(l == r){
return ;
}
int mid = l + r >> 1;
s[mid][mid] = a[mid];
for(int i = mid + 1 ; i <= r ; ++i){
if(s[i][mid + 1] == -1)s[mid][i] = Secret(s[mid][i - 1] , a[i]);
else s[mid][i] = s[i][mid + 1];
}
s[mid][mid - 1] = a[mid - 1];
for(int i = mid - 2 ; i >= l ; --i){
if(s[i][mid - 1] == -1)s[mid][i] = Secret(a[i] , s[mid][i + 1]);
else s[mid][i] = s[i][mid - 1];
}
for(int i = l ; i <= r ; ++i){
if(s[mid][i] == -1)cout << s[mid][i] << endl;
}
Build(x * 2 , l , mid);
Build(x * 2 + 1 , mid + 1 , r);
}
void Init(int N, int A[]) {
memset(s,-1,sizeof s);
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){
if(L == mid){
return s[mid][R];
}
return Secret(s[mid][L],s[mid][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;
if(L == R)return a[L];
int res = query(1 , 1 , n , L , R);
return res;
}
Compilation message
secret.cpp: In function 'void Build(int, int, int)':
secret.cpp:14: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:42:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
186 ms |
18340 KB |
Output is correct - number of calls to Secret by Init = 3331, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
186 ms |
18332 KB |
Output is correct - number of calls to Secret by Init = 3340, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
186 ms |
18296 KB |
Output is correct - number of calls to Secret by Init = 3348, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
613 ms |
20216 KB |
Output is correct - number of calls to Secret by Init = 7467, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
615 ms |
20340 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
628 ms |
20136 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
617 ms |
20388 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
615 ms |
20216 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
617 ms |
20252 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
615 ms |
20236 KB |
Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1 |