# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
487190 |
2021-11-14T19:07:34 Z |
Victor |
Secret (JOI14_secret) |
C++17 |
|
446 ms |
8260 KB |
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
int prefix[1001][1001], nums[1001];
int n;
void populate(int L, int R) {
int mid = (L + R) / 2;
prefix[mid][mid] = nums[mid];
prefix[mid + 1][mid + 1] = nums[mid + 1];
for (int i = mid + 2; i <= R; i++)
prefix[mid + 1][i] = Secret(prefix[mid + 1][i - 1], nums[i]);
for (int i = mid - 1; i >= L; i--)
prefix[mid][i] = Secret(nums[i], prefix[mid][i + 1]);
if (L < mid) populate(L, mid);
if (mid + 1 < R) populate(mid + 1, R);
}
void Init(int N, int A[]) {
memset(prefix, -1, sizeof(prefix));
rep(i, 0, N) nums[i] = A[i];
populate(0, N - 1);
n = N;
}
int Query(int L, int R) {
if (L == R) return nums[L];
int lo = 0, hi = n - 1;
while (1) {
int mid = (lo + hi) / 2;
if (L <= mid && mid < R) return Secret(prefix[mid][L], prefix[mid + 1][R]);
if (R == mid) return prefix[mid][L];
if (mid < L)
lo = mid + 1;
else
hi = mid;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
6280 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
122 ms |
6228 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
122 ms |
6284 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
428 ms |
8164 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
446 ms |
8192 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
426 ms |
8260 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
427 ms |
8172 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
438 ms |
8260 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
442 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 |
432 ms |
8256 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |