#include "secret.h"
#include<bits/stdc++.h>
using namespace std ;
const int mx = 1024 ;
int pre[mx][mx] , a[mx] , n ;
void dnc(int l , int r , int d)
{
if(l+1==r) return ;
if(l==r) return ;
int mid = (l+r)/2 ;
pre[d][mid] = a[mid] ;
for(int i = mid - 1 ; i >= l ; --i)
{
pre[d][i] = Secret(a[i],pre[d][i+1]) ;
}
pre[d][mid+1] = a[mid+1] ;
for(int i = mid + 2 ; i <= r ; ++i)
{
pre[d][i] = Secret(pre[d][i-1],a[i]) ;
}
dnc(l,mid,d+1) , dnc(mid+1,r,d+1) ;
}
void Init(int N , int A[])
{
n = N ;
for(int i = 0 ; i < N ; ++i) a[i] = A[i] ;
dnc(0,N-1,0) ;
}
int dq_c(int l , int r , int ql , int qr , int d)
{
int mid = (l+r)/2 ;
if((ql<=mid&&qr>mid))
{
return Secret(pre[d][ql],pre[d][qr]) ;
}
if(qr==mid) return pre[d][ql] ;
if(qr<=mid) return dq_c(l,mid,ql,qr,d+1) ;
else return dq_c(mid+1,r,ql,qr,d+1) ;
}
int Query(int L , int R)
{
if(L==R) return a[L] ;
if(L+1==R) return Secret(a[L],a[R]) ;
return dq_c(0,n-1,L,R,0) ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
2412 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 |
2412 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
143 ms |
2412 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
502 ms |
4456 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
507 ms |
4352 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
515 ms |
4448 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
507 ms |
4516 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
502 ms |
4460 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
506 ms |
4460 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
510 ms |
4332 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |