Skip to content

300. Longest Increasing Subsequence#29

Open
hroc135 wants to merge 3 commits intomainfrom
300LongestIncreasingSubsequence
Open

300. Longest Increasing Subsequence#29
hroc135 wants to merge 3 commits intomainfrom
300LongestIncreasingSubsequence

Conversation

@hroc135
Copy link
Copy Markdown
Owner

@hroc135 hroc135 commented Dec 19, 2024

- pros and cons
- セグ木の方ができることが多い。
BITは逆元がない演算はできないので累積和くらいにしか使えないと書いてあったが、
逆元のないmaxを実装できてしまったのでよくわからない。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

通常は、任意の範囲での max を計算したかったりします。任意の範囲で逆元がない演算で結合した結果が欲しいときの話でしょう。
たとえば、一番下のノード以外の範囲の max を計算しようとすると BIT だとちょっと大変です。ただ、今回は、一番下を含む範囲しか計算しないので BIT でもいいですね。

var updateHelper func(index, left, right int)
updateHelper = func(index, left, right int) {
if targetIndex == left && targetIndex == right {
st.tree[index] = max(st.tree[index], value)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ここ、max にしていますが減ることがあっても構わない気がしています。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

本当ですね、st.tree[index] = value で動きました

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.

2 participants