diff options
author | Xiaoxu Guo <shimo11370@proton.me> | 2024-08-03 15:28:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-03 15:28:00 +0800 |
commit | b36afe858a64e134b6035d9698fd55a8267a6545 (patch) | |
tree | d386e73a5883a307a494b292c9b5ccc44184969a | |
parent | fc1c261147275c9c2c3931077a362a20fac49020 (diff) | |
parent | 42ceb770b649c8b39b7520a5c28bb21f7c0f65df (diff) | |
download | shoka-master.tar.gz shoka-master.zip |
make stack smaller
-rw-r--r-- | cartesian.h | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/cartesian.h b/cartesian.h index 4108d3f..fc2780e 100644 --- a/cartesian.h +++ b/cartesian.h @@ -14,14 +14,13 @@ class MaxCartesianTree { public: explicit MaxCartesianTree(std::ranges::random_access_range auto a, C compare = {}) - : n(std::ranges::size(a)), stack(n + 1), root{-1}, child(n) { - int top = 0; - stack[0] = -1; + : n(std::ranges::size(a)), stack(n), root{-1}, child(n) { + int top = -1; for (int i = 0; i < n; i++) { - while (~stack[top] && compare(a[stack[top]], a[i])) { + while (~top && compare(a[stack[top]], a[i])) { top--; } - int &r = top ? child[stack[top]][1] : root; + int &r = ~top ? child[stack[top]][1] : root; child[i] = {r, -1}; r = i; stack[++top] = i; |