#include "secret.h"
#include <bits/stdc++.h>
using namespace std ;
map< pair<int,int> , long long > mp ;
void divideConquer(int l, int r )
{
if( r-l+1 < 2 ) return ;
int mid = (r+l)>>1 ;
for(int i = mid+2 ; i <= r ; i++ )
mp[ make_pair(mid+1,i) ] = Secret(mp[make_pair(mid+1,i-1)], mp[ make_pair(i,i) ] ) ;
for(int i = mid-1 ; i >= l ; i-- )
mp[ make_pair(i,mid) ] = Secret(mp[ make_pair(i,i) ],mp[make_pair(i+1,mid)] ) ;
divideConquer(l, mid-1) ;
divideConquer(mid+2, r) ;
}
void Init(int N, int A[])
{
for(int i = 0 ; i < N ; i++ ) mp[ make_pair(i,i) ] = A[i] ;
divideConquer(0, N-1 ) ;
}
int Query(int L, int R)
{
for(int i= L ; i < R ; i++ )
{
auto lef = mp.find(make_pair(L,i) ) ;
auto rig = mp.find(make_pair(i+1, R) ) ;
if(lef == mp.end() || rig == mp.end() ) continue ;
return Secret( lef->second , rig->second ) ;
}
if( L == R ) return mp[ make_pair(L,L) ] ;
}
Compilation message
secret.cpp: In function 'int Query(int, int)':
secret.cpp:50:1: warning: control reaches end of non-void function [-Wreturn-type]
50 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
2668 KB |
Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
223 ms |
2668 KB |
Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
224 ms |
2796 KB |
Output is correct - number of calls to Secret by Init = 3100, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
681 ms |
4996 KB |
Output is correct - number of calls to Secret by Init = 6988, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
675 ms |
5100 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
509 ms |
5128 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
906 ms |
5188 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
916 ms |
4844 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
897 ms |
4972 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
898 ms |
4972 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |