#include<bits/stdc++.h>
#include "secret.h"
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5 + 5, inf = 1e9;
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define sz(x) (int)x.size()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int ans[1005][1005];
void solve(int l, int r, int a[]){
if(l == r){
return;
}
int mid = (l + r) / 2;
for(int i = mid - 1; i >= l; i--){
ans[i][mid] = Secret(a[i], ans[i + 1][mid]);
}
for(int i = mid + 2; i <= r; i++){
ans[mid + 1][i] = Secret(ans[mid + 1][i - 1], a[i]);
}
solve(l, mid, a);
solve(mid + 1, r, a);
}
void Init(int n, int a[]){
memset(ans, -1, sizeof ans);
for(int i = 0; i < n; i++)ans[i][i] = a[i];
solve(0, n - 1, a);
}
int Query(int ql, int qr){
if(ans[ql][qr] != -1)return ans[ql][qr];
for(int i = ql; i < qr; i++){
if(ans[ql][i] != -1 && ans[i + 1][qr] != -1){
return Secret(ans[ql][i], ans[i + 1][qr]);
}
}
}
Compilation message
secret.cpp: In function 'int Query(int, int)':
secret.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
6392 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
158 ms |
6392 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
157 ms |
6392 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
533 ms |
8440 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
545 ms |
8440 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
532 ms |
8312 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
535 ms |
8324 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
536 ms |
8312 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
541 ms |
8312 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
540 ms |
8312 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |