#include "secret.h"
#include <cstring>
#include <cstdio>
#include <algorithm>
int arr[1005][1005];
int n;
void get(int i,int j){
if (arr[i][j]!=-1) return;
else if (arr[i+1][j]!=-1) arr[i][j]=Secret(arr[i][i],arr[i+1][j]);
else arr[i][j]=Secret(arr[i][j-1],arr[j][j]);
}
void Init(int N, int a[]) {
n=N;
memset(arr,-1,sizeof(arr));
for (int x=0;x<n;x++) arr[x][x]=a[x];
int l,r;
bool flag;
for (int x=2;x<=n;x<<=1){
l=0,r=x-1;
flag=true;
while (l<n){
if (flag){
for (int i=r;i>=l;i--) get(i,r);
}
else{
for (int i=l;i<=r;i++) get(l,i);
}
l+=x;
r=std::min(r+x,n-1);
flag^=true;
}
}
}
int Query(int l, int r) {
if (arr[l][r]!=-1) return arr[l][r];
for (int x=l;x<r;x++){
if (arr[l][x]!=-1 && arr[x+1][r]!=-1) return Secret(arr[l][x],arr[x+1][r]);
}
}
Compilation message
secret.cpp: In function 'int Query(int, int)':
secret.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
6520 KB |
Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
170 ms |
6492 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
173 ms |
6496 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
592 ms |
8472 KB |
Output is correct - number of calls to Secret by Init = 7001, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
586 ms |
8400 KB |
Output is correct - number of calls to Secret by Init = 7008, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
589 ms |
8448 KB |
Output is correct - number of calls to Secret by Init = 7008, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
606 ms |
8256 KB |
Output is correct - number of calls to Secret by Init = 7008, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
603 ms |
8488 KB |
Output is correct - number of calls to Secret by Init = 7008, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
646 ms |
8432 KB |
Output is correct - number of calls to Secret by Init = 7008, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
622 ms |
8440 KB |
Output is correct - number of calls to Secret by Init = 7008, maximum number of calls to Secret by Query = 1 |