# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
914848 |
2024-01-22T18:20:49 Z |
mike |
Secret (JOI14_secret) |
C++14 |
|
390 ms |
9040 KB |
#include <vector>
#include <iostream>
#include "secret.h"
using namespace std;
int tree[4005][1005];
int arr[1005];
int tam;
void segment_tree(int pos, int ini, int fin){
if(ini == fin){
tree[pos][ini]=arr[ini];
return;
}
if(ini == fin-1){
tree[pos][ini]=arr[ini];
tree[pos][fin]=arr[fin];
return;
}
int mitad=(ini+fin)/2;
tree[pos][mitad-1]=arr[mitad-1];
for(int c=mitad-2; c >= ini; c--){
tree[pos][c]=Secret(arr[c], tree[pos][c+1]);
}
tree[pos][mitad]=arr[mitad];
for(int c=mitad+1; c <= fin; c++){
tree[pos][c]=Secret(tree[pos][c-1],arr[c]);
}
segment_tree(pos*2, ini, mitad);
segment_tree(pos*2+1, mitad+1, fin);
}
void Init(int N, int A[]){
tam=N;
for(int c=0; c < N; c++){
arr[c]=A[c];
}
segment_tree(1, 0, N-1);
}
int ayuda(int pos, int ini, int fin, int l, int r){
int mitad=(ini+fin)/2;
if(l == r)
return arr[l];
if(l == r-1)
return Secret(arr[l], arr[r]);
if(l < mitad && r >= mitad){
return Secret(tree[pos][l], tree[pos][r]);
}
if(l==mitad)return tree[pos][r];
if(r == mitad-1) return tree[pos][l];
if(l >= mitad){
return ayuda(pos*2+1, mitad+1, fin, l, r);
}
else
return ayuda(pos*2, ini, mitad, l , r);
}
int Query(int L, int R){
if(L == R)
return arr[L];
if(L == R-1)
return Secret(arr[L], arr[R]);
return ayuda(1, 0, tam-1, L, R);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
6740 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 |
6752 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
109 ms |
6652 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
382 ms |
9040 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
384 ms |
8788 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
380 ms |
8792 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
380 ms |
8792 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
390 ms |
8876 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
381 ms |
8792 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
382 ms |
8792 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |