#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;
#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
/////// SOLUTION \\\\\\\
const int MAX_N = 1111;
int a[1111];
int n;
int range[MAX_N][MAX_N];
void build(int l, int r)
{
if(r - l < 2)
return ;
int m = (l+r)/2;
for(int i = m-1; i >=l; i--)
{
if(range[i][m] != -1) continue;
range[i][m] = Secret(range[i][i],range[i+1][m]);
}
for(int i = m +2; i <=r; i ++)
{
if(range[m+1][i] != -1) continue;
range[m+1][i] = Secret(range[m+1][i-1],range[i][i]);
}
build(l,m-1);
build(m+1,r);
}
void Init(int N, int A[])
{
n = N;
for(int i= 0; i <n; i ++)
a[i] = A[i];
for(int i = 0; i <n; i ++)
for(int j= 0; j <n; j ++)
range[i][j] = -1;
for(int i= 0; i <n; i ++)
range[i][i] = a[i];
build(0,n-1);
}
int Query(int l, int r)
{
if(range[l][r] != -1) return range[l][r];
for(int i = l; i <r; i++)
{
if(range[l][i] != -1 && range[i+1][r] != -1)
return range[l][r]= Secret(range[l][i],range[i+1][r]);
}
}
/*int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tt;
while(tt--)
{
solve();
}
}*/
Compilation message
secret.cpp:26:1: warning: multi-line comment [-Wcomment]
26 | /////// SOLUTION \\\\\\\
| ^
secret.cpp: In function 'int Query(int, int)':
secret.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
71 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
4528 KB |
Output is correct - number of calls to Secret by Init = 3084, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
123 ms |
4508 KB |
Output is correct - number of calls to Secret by Init = 3092, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
131 ms |
4560 KB |
Output is correct - number of calls to Secret by Init = 3100, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
437 ms |
8632 KB |
Output is correct - number of calls to Secret by Init = 6988, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
428 ms |
8660 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
426 ms |
8676 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
428 ms |
8644 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
429 ms |
8516 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
435 ms |
8568 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
432 ms |
8512 KB |
Output is correct - number of calls to Secret by Init = 6996, maximum number of calls to Secret by Query = 1 |