# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
974864 | aaaaaarroz | Secret (JOI14_secret) | C++17 | 406 ms | 6484 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 Secret(int l, int r);
map<pair<int,int>,int>dp;
map<pair<int,int>,bool>calculed;
template<class T, T m_(T, T)> struct SegmentTree{
int n; vector<T> ST;
SegmentTree(){}
SegmentTree(vector<T> &a){
n = a.size(); ST.resize(n << 1);
for (int i=n;i<(n<<1);i++)ST[i]=a[i-n];
for (int i=n-1;i>0;i--)ST[i]=m_(ST[i<<1],ST[i<<1|1]);
}
void update(int pos, T val){ // replace with val
ST[pos += n] = val;
for (pos >>= 1; pos > 0; pos >>= 1)
ST[pos] = m_(ST[pos<<1], ST[pos<<1|1]);
}
T query(int l, int r){ // [l, r]
T ansL, ansR; bool hasL = 0, hasR = 0;
for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
ansL=(hasL?m_(ansL,ST[l++]):ST[l++]),hasL=1;
if (r & 1)
ansR=(hasR?m_(ST[--r],ansR):ST[--r]),hasR=1;
}
if (!hasL) return ansR; if (!hasR) return ansL;
return m_(ansL, ansR);
}
}; // Give vector of leaves and merge function
int merge(int a,int b){
if(calculed[{a,b}]){
return dp[{a,b}];
}
dp[{a,b}]=Secret(a,b);
calculed[{a,b}]=true;
return dp[{a,b}];
}
vector<int>AA;
SegmentTree<int,merge>st(AA);
void Init(int n, int a[]){
vector<int>arr(n);
for(int i=0;i<n;i++){
arr[i]=a[i];
}
SegmentTree<int,merge>stt(arr);
st=stt;
}
int Query(int l,int r){
return st.query(l,r);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |