Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Sort Tree #106

Merged
merged 11 commits into from
Mar 18, 2024
Merged

Merge Sort Tree #106

merged 11 commits into from
Mar 18, 2024

Conversation

shogo314
Copy link
Member

@shogo314 shogo314 commented Mar 8, 2024

No description provided.

}
}

if (i < n) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i < nじゃないことはありますか。

}
}

value_type _prod_section(int l, int r, std::optional<key_type> a, std::optional<key_type> b) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aもbもnullならeではなく総積を返してほしくないですか。
初期値を総積にしておいてbのほうもhas_value()で右側範囲の逆元をかけると良いと思います。

int last1 = j2;
int last2 = h * sz + std::min(n, i + t * 2);
while (j1 != last1 or j2 != last2) {
if (j1 == last1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

特別気にしないのでそのままでもいいですが、同じことが2回ずつ書いてあると写経でミスする可能性が大きくなるのでj1 == last || (j2 < last && cmp(key_data[j2], key_data[j1])などとすると簡潔そうです。

/**
* @brief product value[i] s.t. a <= key[i] < b , i in [l, r)
*/
value_type prod(std::optional<int> l = std::nullopt, std::optional<int> r = std::nullopt, std::optional<key_type> a = std::nullopt, std::optional<key_type> b = std::nullopt) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

セグ木にassertを入れたのでここでも入れると良さそうです。

@shogo314
Copy link
Member Author

指摘を反映しました。
lとrは必ずしもoptionalである必要はないので、segtree等に合わせて変更しました。
assert(l<=r); と if(a>=b) return e();
は自分からすると十分共存し得るのですがどう思いますか

Copy link
Contributor

@KowerKoint KowerKoint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OKです

@KowerKoint KowerKoint merged commit 8e842de into main Mar 18, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants