-
Notifications
You must be signed in to change notification settings - Fork 27
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
Segtree: Monoid BitwiseOr/BitwiseAnd/BitwiseXor, get_slice #115
Conversation
The following code keeps the segtree implementation, but changes the input/output processing. |
For the |
src/segtree.rs
Outdated
@@ -68,6 +68,48 @@ where | |||
} | |||
} | |||
|
|||
pub struct BitOrOper<S>(Infallible, PhantomData<fn() -> S>); |
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.
This is just a matter of preference, but I prefer BitwiseOr
. ("Operation" is obvious in the context, while "bit or" is kinda misleading (are we handling a single bit?))
src/segtree.rs
Outdated
@@ -107,6 +149,10 @@ impl<M: Monoid> Segtree<M> { | |||
self.d[p + self.size].clone() | |||
} | |||
|
|||
pub fn get_slice(&self) -> &[M::S] { | |||
&self.d[self.size..(self.size + self.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.
Just showing off a trick: did you know that you can write like this 😜? (I prefer this style becuase you need to specify the same variable twice.)
&self.d[self.size..(self.size + self.n)] | |
&self.d[self.size..][..self.n] |
src/segtree.rs
Outdated
{ | ||
type S = S; | ||
fn identity() -> Self::S { | ||
S::default() |
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.
I'm still doubting if we should use "Default" in this case, considering the semantics. (See also my previous comment).
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.
LGTM
usage sample: ABC285F - Substring of Sorted String
https://atcoder.jp/contests/abc285/submissions/38317831