# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735756 | Toxtaq | Secret (JOI14_secret) | C++17 | 515 ms | 4488 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<bits/stdc++.h>
using namespace std;
int n;
int Secret(int X, int Y);
struct SegmentTree{
vector<int>segTree;
void init(int n){
segTree.resize(4 * n);
}
void Build(int node, int l, int r, vector<int>&v){
if(l == r)segTree[node] = v[l];
else{
int mid = (l + r) >> 1;
Build(node * 2, l, mid, v);
Build(node * 2 + 1, mid + 1, r, v);
segTree[node] = Secret(segTree[node * 2], segTree[node * 2 + 1]);
}
}
int Query(int node, int l, int r, int ql, int qr){
if(ql <= l && r <= qr)return segTree[node];
if(ql > r || l > qr)return -1;
int mid = (l + r) >> 1;
int lc = Query(node * 2, l, mid, ql, qr);
int rc = Query(node * 2 + 1, mid + 1, r, ql, qr);
if(lc == -1)return rc;
if(rc == -1)return lc;
return Secret(lc, rc);
}
};
SegmentTree tree;
void Init(int N, int A[]) {
n = N;
vector<int>v(n + 1);
for(int i = 1;i <= n;++i){
v[i] = A[i - 1];
}
tree.init(n);
tree.Build(1, 1, n, v);
}
int Query(int L, int R) {
return tree.Query(1, 1, n, L + 1, R + 1);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |