# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
866006 |
2023-10-25T09:43:56 Z |
lolismek |
Secret (JOI14_secret) |
C++14 |
|
397 ms |
4488 KB |
#include "secret.h"
#include <vector>
#include <iostream>
using namespace std;
const int NMAX = 2000;
int n;
int a[NMAX + 1];
int dp[20][NMAX + 1];
void divide(int level, int l, int r){
if(l == r){
dp[level][l] = a[l];
return;
}
int mid = (l + r) / 2;
dp[level][mid] = a[mid];
for(int i = mid - 1; i >= l; i--){
dp[level][i] = Secret(a[i], dp[level][i + 1]);
}
if(mid + 1 <= r){
dp[level][mid + 1] = a[mid + 1];
}
for(int i = mid + 2; i <= r; i++){
dp[level][i] = Secret(dp[level][i - 1], a[i]);
}
divide(level + 1, l, mid);
divide(level + 1, mid + 1, r);
}
void Init(int N, int A[]){
n = N;
for(int i = 0; i < N; i++){
a[i] = A[i];
}
divide(1, 0, N - 1);
}
int getAns(int level, int l, int r, int L, int R){
int mid = (l + r) / 2;
if(L <= mid && mid <= R){
if(R == mid){
return dp[level][L];
}
return Secret(dp[level][L], dp[level][R]);
}
if(mid < L){
return getAns(level + 1, mid + 1, r, L, R);
}
return getAns(level + 1, l, mid, L, R);
}
int Query(int L, int R){
if(L == R){
return a[L];
}
return getAns(1, 0, n - 1, L, R);
}
/*
5
1 2 3 4 5
1
3 4
1000
1
0 999
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
2648 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
109 ms |
2992 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
108 ms |
2652 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
397 ms |
4272 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
388 ms |
4268 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
378 ms |
4264 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
382 ms |
4488 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
380 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
388 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
383 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |