teamnote default
This commit is contained in:
13
source/Technic/CartesianTree.cpp
Normal file
13
source/Technic/CartesianTree.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
int A[N], par[N];
|
||||
stack<int> st;
|
||||
forr(i, n) {
|
||||
int l = -1;
|
||||
while(!st.empty() && A[st.top()] < A[i])
|
||||
l = st.top(), st.pop();
|
||||
if(l != -1) par[l] = i;
|
||||
if(!st.empty()) par[i] = st.top();
|
||||
st.push(i);
|
||||
}
|
||||
|
||||
while(st.size() != 1) st.pop();
|
||||
par[st.top()] = st.top();
|
||||
Reference in New Issue
Block a user