Difference between revisions of "Cartesian Tree"
Jump to navigation
Jump to search
(Created page with "{{Quote|text=Have no idea how to use it.|source=ultmaster}} <syntaxhighlight lang='cpp'> int main() { int n; int p = 0, rt = 0; int now[maxn], h[maxn], lc[maxn],...") |
|||
Line 1: | Line 1: | ||
− | + | Have no idea how to use it. (by ultmaster) | |
<syntaxhighlight lang='cpp'> | <syntaxhighlight lang='cpp'> |
Latest revision as of 12:31, 22 March 2018
Have no idea how to use it. (by ultmaster)
int main() {
int n;
int p = 0, rt = 0;
int now[maxn], h[maxn], lc[maxn], rc[maxn];
for (int i = 1; i <= n; i++) {
int last = 0;
while (p && h[now[p]] >= h[i]) {
last = now[p];
now[p--] = 0;
}
if (p) rc[now[p]] = i;
else rt = i;
lc[i] = last;
now[++p] = i;
}
}