Submission #735756

#TimeUsernameProblemLanguageResultExecution timeMemory
735756ToxtaqSecret (JOI14_secret)C++17
30 / 100
515 ms4488 KiB
#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 timeMemoryGrader output
Fetching results...