-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add segment tree #22
base: master
Are you sure you want to change the base?
Add segment tree #22
Conversation
テストできるようになったと思います |
buildが変わっていないみたいでダメでした.
と出ます. |
|
|
|
798aec0 |
あー本当だ、申し訳ない 🙇 |
SegmentTree(vector<Monoid> vec, const Func f, const Monoid identityElement); | ||
void Update(int idx, Monoid val); | ||
Monoid Query(int a, int b, int k = 0, int l = 0, | ||
int r = -1); // 使う時は区間[a, b)のみ指定すれば良い |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あれここ r=-1
でよかったっけと思ったら47行目で r=n;
してるのか
}; | ||
|
||
template <typename Monoid> | ||
SegmentTree<Monoid>::SegmentTree(vector<Monoid> vec, const Func f, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
単純な疑問で、なんで第一引数にvecと受け取るようにしたか知りたいです
特に配列の大きさNを渡すだけと比べて何が違うのか
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
事前に生成された配列の区間に対するQueryが高速に欲しい場合に,Update関数を用いてセグ木を作るより,配列からセグ木を作るほうが手間が省けると考えたためです.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど
|
||
template <typename Monoid> | ||
Monoid SegmentTree<Monoid>::Query(int a, int b, int k, int l, int r) { | ||
if (r < 0) r = n; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここは写経するときに見落としてバグりそうな気がするので、 Query(int, int, int, int, int)
を query(int, int, int, int, int)
としてprivateに移動し、 publicに Query(int, int)
という関数を新しく用意するのはどうでしょうか?
No description provided.