# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
368058 |
2021-02-19T12:03:12 Z |
RyoPham |
Secret (JOI14_secret) |
C++14 |
|
528 ms |
4800 KB |
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
#define sz(x) (int)x.size()
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 1005;
int n;
int a[maxn], B[maxn];
vector<int> left_val[maxn * 4], right_val[maxn * 4];
int cnt = 0;
void dnc(int x, int l, int r)
{
if(l == r) return;
int mid = (l + r) / 2;
left_val[x].push_back(a[mid]);
for(int i = mid - 1; i >= l; --i)
left_val[x].push_back(Secret(a[i], left_val[x].back()));
right_val[x].push_back(a[mid + 1]);
for(int i = mid + 2; i <= r; ++i)
right_val[x].push_back(Secret(right_val[x].back(), a[i]));
//cnt += sz(left_val[x]) - 1; cnt += sz(right_val[x]) - 1;
dnc(x * 2, l, mid);
dnc(x * 2 + 1, mid + 1, r);
}
int get(int x, int l, int r, int L, int R)
{
assert(l < r);
int mid = (l + r) / 2;
if(L <= mid && R > mid)
return Secret(left_val[x][mid - L], right_val[x][R - mid - 1]);
if(R <= mid)
return get(x * 2, l, mid, L, R);
return get(x * 2 + 1, mid + 1, r, L, R);
}
void Init(int N, int A[])
{
n = N;
for(int i = 0; i < n; ++i)
a[i] = A[i];
dnc(1, 0, n - 1);
}
int Query(int L, int R)
{
if(L == R) return a[L];
return get(1, 0, n - 1, L, R);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
2668 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
144 ms |
2668 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
144 ms |
2776 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
511 ms |
4580 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
511 ms |
4588 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
528 ms |
4588 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
521 ms |
4716 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
513 ms |
4588 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
523 ms |
4716 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
519 ms |
4800 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |