# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25258 | tlwpdus | Secret (JOI14_secret) | C++14 | 626 ms | 6256 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[1100];
struct node {
vector<int> l, r;
};
struct idxtree {
node tree[2100];
void init(int s, int e, int idx) {
if (s==e) {
tree[idx].l.push_back(arr[s]);
tree[idx].r.push_back(arr[s]);
return;
}
int i, m = (s+e)>>1;
init(s,m,idx*2);
init(m+1,e,idx*2+1);
if (idx==1) return;
for (i=s;i<=m;i++) tree[idx].l.push_back(tree[idx*2].l[i-s]);
for (i=m+1;i<=e;i++) tree[idx].l.push_back(Secret(tree[idx].l.back(),arr[i]));
for (i=e;i>m;i--) tree[idx].r.push_back(tree[idx*2+1].r[e-i]);
for (i=m;i>s;i--) tree[idx].r.push_back(Secret(arr[i],tree[idx].r.back()));
tree[idx].r.push_back(tree[idx].l.back());
}
int getv(int s, int e, int idx, int S, int E) {
int m = (s+e)>>1;
if (s==e) return arr[s];
if (E<=m) return getv(s,m,idx*2,S,E);
else if (m+1<=S) return getv(m+1,e,idx*2+1,S,E);
else return Secret(tree[idx*2].r[m-S],tree[idx*2+1].l[E-m-1]);
}
} it;
void Init(int N, int A[]) {
n = N;
int i;
for (i=0;i<n;i++) arr[i]=A[i];
it.init(0,n-1,1);
}
int Query(int L, int R) {
return it.getv(0,n-1,1,L,R);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |