# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
553669 |
2022-04-26T13:54:13 Z |
QwertyPi |
Secret (JOI14_secret) |
C++14 |
|
512 ms |
5324 KB |
#include "secret.h"
#include <bits/stdc++.h>
#define MAXN 1001
using namespace std;
int N;
int A[MAXN];
vector<int> pf[MAXN * 4], sf[MAXN * 4];
map<pair<int, int>, int> memo;
void build(int v = 0, int l = 0, int r = N - 1){
pf[v].resize(r - l + 1);
sf[v].resize(r - l + 1);
pf[v][0] = A[l];
for(int i = 1; i <= r - l; i++){
pf[v][i] = memo.find({l, l + i}) != memo.end() ? memo[{l, l + i}] : Secret(pf[v][i - 1], A[l + i]);
}
sf[v][r - l] = A[r];
for(int i = r - l - 1; i >= 0; i--){
sf[v][i] = memo.find({l + i, r}) != memo.end() ? memo[{l + i, r}] : Secret(A[l + i], sf[v][i + 1]);
}
for(int i = 0; i <= r - l; i++){
memo[{l, l + i}] = pf[v][i];
memo[{l + i, r}] = sf[v][i];
}
if(l != r){
int m = (l + r) / 2;
build(v * 2 + 1, l, m);
build(v * 2 + 2, m + 1, r);
}
}
int qry(int l, int r, int v = 0, int tl = 0, int tr = N - 1){
int tm = (tl + tr) / 2;
if(l == r) return A[l];
if(l <= tm && tm < r){
return Secret(sf[v * 2 + 1][l - tl], pf[v * 2 + 2][r - (tm + 1)]);
}
if(r <= tm){
return qry(l, r, v * 2 + 1, tl, tm);
}else{
return qry(l, r, v * 2 + 2, tm + 1, tr);
}
}
void Init(int N, int A[]) {
::N = N;
for(int i = 0; i < N; i++) ::A[i] = A[i];
build();
}
int Query(int L, int R) {
return qry(L, R);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
2920 KB |
Output is correct - number of calls to Secret by Init = 4089, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
155 ms |
2884 KB |
Output is correct - number of calls to Secret by Init = 4098, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
127 ms |
2916 KB |
Output is correct - number of calls to Secret by Init = 4108, maximum number of calls to Secret by Query = 1 |
4 |
Partially correct |
456 ms |
5172 KB |
Output isn't correct - number of calls to Secret by Init = 8968, maximum number of calls to Secret by Query = 1 |
5 |
Partially correct |
449 ms |
5324 KB |
Output isn't correct - number of calls to Secret by Init = 8978, maximum number of calls to Secret by Query = 1 |
6 |
Partially correct |
468 ms |
5292 KB |
Output isn't correct - number of calls to Secret by Init = 8978, maximum number of calls to Secret by Query = 1 |
7 |
Partially correct |
512 ms |
5260 KB |
Output isn't correct - number of calls to Secret by Init = 8978, maximum number of calls to Secret by Query = 1 |
8 |
Partially correct |
445 ms |
5180 KB |
Output isn't correct - number of calls to Secret by Init = 8978, maximum number of calls to Secret by Query = 1 |
9 |
Partially correct |
474 ms |
5220 KB |
Output isn't correct - number of calls to Secret by Init = 8978, maximum number of calls to Secret by Query = 1 |
10 |
Partially correct |
478 ms |
5260 KB |
Output isn't correct - number of calls to Secret by Init = 8978, maximum number of calls to Secret by Query = 1 |