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

Segtree: Monoid BitwiseOr/BitwiseAnd/BitwiseXor, get_slice #115

Merged
merged 3 commits into from
Apr 16, 2023

Conversation

mizar
Copy link
Collaborator

@mizar mizar commented Jan 25, 2023

  • Monoid BitOrOper/BitAndOper/BitXorOper: for bool/bitset type segtree data
  • FromIterator: struct from Iterator
  • get_slice: allows slice access to internal data

usage sample: ABC285F - Substring of Sorted String
https://atcoder.jp/contests/abc285/submissions/38317831

@mizar
Copy link
Collaborator Author

mizar commented Jan 25, 2023

The following code keeps the segtree implementation, but changes the input/output processing.
https://atcoder.jp/contests/abc285/submissions/38318119

@mizar
Copy link
Collaborator Author

mizar commented Mar 27, 2023

For the FromIterator, the following PR exists, so I'll just Revert it here
#107

src/segtree.rs Outdated
@@ -68,6 +68,48 @@ where
}
}

pub struct BitOrOper<S>(Infallible, PhantomData<fn() -> S>);
Copy link
Collaborator

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)]
Copy link
Collaborator

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.)

Suggested change
&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()
Copy link
Collaborator

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).

Copy link
Collaborator

@TonalidadeHidrica TonalidadeHidrica left a comment

Choose a reason for hiding this comment

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

LGTM

@TonalidadeHidrica TonalidadeHidrica changed the title Segtree: Monoid BitOrOper/BitAndOper/BitXorOper, FromIterator, get_slice Segtree: Monoid BitwiseOr/BitwiseAnd/BitwiseXor, get_slice Apr 16, 2023
@TonalidadeHidrica TonalidadeHidrica merged commit 33dc514 into rust-lang-ja:master Apr 16, 2023
@mizar mizar deleted the segtree branch April 16, 2023 22:36
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