aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiaoxu Guo <shimo11370@proton.me>2024-08-03 15:28:00 +0800
committerGitHub <noreply@github.com>2024-08-03 15:28:00 +0800
commitb36afe858a64e134b6035d9698fd55a8267a6545 (patch)
treed386e73a5883a307a494b292c9b5ccc44184969a
parentfc1c261147275c9c2c3931077a362a20fac49020 (diff)
parent42ceb770b649c8b39b7520a5c28bb21f7c0f65df (diff)
downloadshoka-master.tar.gz
shoka-master.zip
Merge pull request #3 from MaskRay/cartesianHEADmaster
make stack smaller
-rw-r--r--cartesian.h9
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;