#include "secret.h"
int n, a[1000], pre[1000][1000];
void build(int l, int r)
{
if (l+1>=r)
return;
int m=l+(r-l)/2;
pre[m][m]=a[m];
pre[m+1][m+1]=a[m+1];
for (int i=m-1;i>=l;--i)
pre[i][m]=Secret(a[i],pre[i+1][m]);
for (int i=m+2;i<=r;++i)
pre[m+1][i]=Secret(pre[m+1][i-1],a[i]);
build(l,m);
build(m+1,r);
}
void Init(int N, int A[])
{
n=N;
for (int i=0;i<n;++i)
a[i]=A[i];
build(0,n-1);
}
int Query(int l, int r)
{
if (l==r)
return a[l];
if (l+1==r)
return Secret(a[l],a[r]);
int x=0, y=n-1, m;
while (1)
{
m=x+(y-x)/2;
if (l<=m&&m<r)
return Secret(pre[l][m],pre[m+1][r]);
if (m<l)
x=m+1;
else
y=m;
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
4308 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
143 ms |
4300 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 |
4260 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
526 ms |
8148 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
541 ms |
8132 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
522 ms |
8100 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
522 ms |
8176 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
530 ms |
8132 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
522 ms |
8132 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
519 ms |
8092 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |