-
Notifications
You must be signed in to change notification settings - Fork 30
Implement segtree #37
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
Merged
qryxip
merged 23 commits into
rust-lang-ja:master
from
TonalidadeHidrica:feature/segtree
Sep 17, 2020
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0e8242f
Initial commit for segtree
TonalidadeHidrica 452f9f1
Added segtree
TonalidadeHidrica c35995e
Removed newline
TonalidadeHidrica 831c35a
Fixed mistakes
TonalidadeHidrica 475676f
Merge branch 'master' into feature/segtree
TonalidadeHidrica db3e57f
Change identity from constant to function
TonalidadeHidrica 7f70828
Added "Max" monoid and a test
TonalidadeHidrica dc64b31
Merge branch 'master' into feature/segtree
TonalidadeHidrica b27d10d
Added sample for J - Segment Tree
TonalidadeHidrica 167cee8
cargo fmt
TonalidadeHidrica 6a6259f
Fixed Default implementation
TonalidadeHidrica dc1c6b7
Changed Copy to Clone
TonalidadeHidrica e6ac534
Renamme test function
TonalidadeHidrica 93a2906
Follow naming convension (mod test -> tests)
TonalidadeHidrica 3a43da6
Change position of newline
TonalidadeHidrica 2e3b0be
Merge branch 'master' into feature/segtree
TonalidadeHidrica ce40d2a
Apply the change that I forgot
TonalidadeHidrica d51a67b
Split integral traits into four subtraits
TonalidadeHidrica 5650b88
Modify binary_operation and add some traits
TonalidadeHidrica 32dbc68
cargo fmt
TonalidadeHidrica 48ceeb6
Changed the signature of f in max_right & min_left
TonalidadeHidrica d4bb776
Changed the monoid namme
TonalidadeHidrica ed778ef
Merge branch 'master' into feature/segtree
TonalidadeHidrica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use ac_library_rs::{Max, Segtree}; | ||
use std::io::Read; | ||
|
||
fn main() { | ||
let mut buf = String::new(); | ||
std::io::stdin().read_to_string(&mut buf).unwrap(); | ||
let mut input = buf.split_whitespace(); | ||
|
||
let n: usize = input.next().unwrap().parse().unwrap(); | ||
let q: usize = input.next().unwrap().parse().unwrap(); | ||
let mut segtree = Segtree::<Max<i32>>::new(n + 1); | ||
for i in 1..=n { | ||
segtree.set(i, input.next().unwrap().parse().unwrap()); | ||
} | ||
for _ in 0..q { | ||
match input.next().unwrap().parse().unwrap() { | ||
1 => { | ||
let x = input.next().unwrap().parse().unwrap(); | ||
let v = input.next().unwrap().parse().unwrap(); | ||
segtree.set(x, v); | ||
} | ||
2 => { | ||
let l = input.next().unwrap().parse().unwrap(); | ||
let r: usize = input.next().unwrap().parse().unwrap(); | ||
println!("{}", segtree.prod(l, r + 1)); | ||
} | ||
3 => { | ||
let x = input.next().unwrap().parse().unwrap(); | ||
let v = input.next().unwrap().parse().unwrap(); | ||
println!("{}", segtree.max_right(x, |a| a < &v)) | ||
} | ||
_ => {} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.