Submission #974840

#TimeUsernameProblemLanguageResultExecution timeMemory
974840aaaaaarrozSecret (JOI14_secret)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; int Secret(int l, int r); template<class T> struct SegmentTree{ T (*merge)(T, T); int n; vector<T>ST; void build(int i, int l, int r, vector<T> &values){ if (l == r){ ST[i] = values[l]; return; } build(i * 2, l, (l + r) / 2, values); build(i * 2 + 1, (l + r) / 2 + 1, r, values); ST[i] = merge(ST[i * 2], ST[i * 2 + 1]); } SegmentTree(vector<T> &values, T (*merge)(T a, T b)) : merge(merge){ n = values.size(); ST.resize(n << 2 | 3); build(1, 0, n - 1, values); } void update(int i, int l, int r, int pos, T val){ if (r < pos or l > pos) return; if (l == r){ ST[i] = val; return; } update(i << 1, l, (l + r) >> 1, pos, val); update(i << 1 | 1, (l + r) / 2 + 1, r, pos, val); ST[i] = merge(ST[i << 1], ST[i << 1 | 1]); } void update(int pos, T val){ update(1, 0, n - 1, pos, val); } T query(int i, int l, int r, int a, int b){ if (l >= a and r <= b) return ST[i]; int mid = (l + r) >> 1; if (mid < a) return query(i << 1 | 1, mid + 1, r, a, b); if (mid >= b) return query(i << 1, l, mid, a, b); return merge(query(i << 1, l, mid, a, b), query(i << 1 | 1, mid + 1, r, a, b)); } T query(int a, int b){ if (a > b) return merge(query(1, 0, n - 1, 0, b), query(1, 0, n - 1, a, n - 1)); return query(1, 0, n - 1, a, b); } }; int merge(int a,int b){ return (Secret(a,b)); } vector<int>A; SegmentTree<int>st(A,merge); void Init(int n, int a[]){ vector<int>arr(n); for(int i=0;i<n;i++){ arr[i]=a[i]; } SegmentTree<int>stt(arr,merge); stt=st; } int Query(int l,int r){ return st.query(l,r); }
#Verdict Execution timeMemoryGrader output
Fetching results...