-
Notifications
You must be signed in to change notification settings - Fork 30
Verify with problems from Library Checker #92
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b798acf
Add `input!` implementation for the examples
qryxip 58c7a9e
Add examples/library-checker-convolution-mod.rs
qryxip 98f4faa
Add examples/library-checker-static-range-sum.rs
qryxip faf6ba0
Add examples/library-checker-sum-of-floor-linear.rs
qryxip 3a1174f
Add examples/library-checker-unionfind.rs
qryxip 6b3a9a0
Verify with problems from Library Checker
qryxip 8f62704
Fix a misspelling
qryxip 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [package] | ||
| name = "input" | ||
| version = "0.1.0" | ||
| authors = ["rust-lang-ja Developers"] | ||
| edition = "2018" | ||
| description = "Provides an `input!` macro for the `examples`." | ||
| license = "CC0-1.0" | ||
| publish = false | ||
|
|
||
| [dependencies] |
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,96 @@ | ||
| //! A simple `input!` macro with minimal functionality. | ||
| //! | ||
| //! ```no_run | ||
| //! #[macro_use] | ||
| //! extern crate input as _; | ||
| //! | ||
| //! fn main() { | ||
| //! input! { | ||
| //! a: [u64], | ||
| //! } | ||
| //! } | ||
| //! ``` | ||
|
|
||
| use std::{ | ||
| fmt, | ||
| io::{self, Read}, | ||
| str::{FromStr, SplitAsciiWhitespace}, | ||
| }; | ||
|
|
||
| #[macro_export] | ||
| macro_rules! input { | ||
| ($($tt:tt)*) => { | ||
| let mut __scanner = $crate::Scanner::new().unwrap(); | ||
| $crate::input_inner!(@scanner(__scanner), @tts($($tt)*)); | ||
| ::std::mem::drop(__scanner); | ||
| }; | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[macro_export] | ||
| macro_rules! input_inner { | ||
| (@scanner($scanner:ident), @tts()) => {}; | ||
| (@scanner($scanner:ident), @tts(mut $single_tt_pat:tt : $readable:tt)) => { | ||
| let mut $single_tt_pat = $crate::read!(from $scanner { $readable }); | ||
| }; | ||
| (@scanner($scanner:ident), @tts($single_tt_pat:tt : $readable:tt)) => { | ||
| let $single_tt_pat = $crate::read!(from $scanner { $readable }); | ||
| }; | ||
| (@scanner($scanner:ident), @tts(mut $single_tt_pat:tt : $readable:tt, $($rest:tt)*)) => { | ||
| $crate::input_inner!(@scanner($scanner), @tts(mut $single_tt_pat: $readable)); | ||
| $crate::input_inner!(@scanner($scanner), @tts($($rest)*)); | ||
| }; | ||
| (@scanner($scanner:ident), @tts($single_tt_pat:tt : $readable:tt, $($rest:tt)*)) => { | ||
| $crate::input_inner!(@scanner($scanner), @tts($single_tt_pat: $readable)); | ||
| $crate::input_inner!(@scanner($scanner), @tts($($rest)*)); | ||
| }; | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| #[macro_export] | ||
| macro_rules! read { | ||
| (from $scanner:ident { [$tt:tt] }) => { | ||
| $crate::read!(from $scanner { [$tt; $crate::read!(from $scanner { usize })] }) | ||
| }; | ||
| (from $scanner:ident { [$tt:tt; $n:expr] }) => { | ||
| (0..$n).map(|_| $crate::read!(from $scanner { $tt })).collect::<Vec<_>>() | ||
| }; | ||
| (from $scanner:ident { ($($tt:tt),+) }) => { | ||
| ($($crate::read!(from $scanner { $tt })),*) | ||
| }; | ||
| (from $scanner:ident { $ty:ty }) => { | ||
| $scanner.parse::<$ty>() | ||
| }; | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| pub struct Scanner { | ||
| words: SplitAsciiWhitespace<'static>, | ||
| } | ||
|
|
||
| impl Scanner { | ||
| pub fn new() -> io::Result<Self> { | ||
| let mut buf = String::with_capacity(1024); | ||
| io::stdin().read_to_string(&mut buf)?; | ||
| let words = Box::leak(buf.into_boxed_str()).split_ascii_whitespace(); | ||
| Ok(Self { words }) | ||
| } | ||
|
|
||
| /// Parses the next word. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if: | ||
| /// | ||
| /// - reached the end of input. | ||
| /// - the word is not successfully parsed. | ||
| pub fn parse<T>(&mut self) -> T | ||
| where | ||
| T: FromStr, | ||
| T::Err: fmt::Display, | ||
| { | ||
| let word = self.words.next().expect("reached the end of input"); | ||
| word.parse() | ||
| .unwrap_or_else(|e| panic!("could not parse {:?}: {}", word, e)) | ||
| } | ||
| } |
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,27 @@ | ||
| #[macro_use] | ||
| extern crate input as _; | ||
|
|
||
| use ac_library_rs::{convolution, modint::ModInt998244353 as Mint}; | ||
| use std::fmt; | ||
|
|
||
| fn main() { | ||
| input! { | ||
| n: usize, | ||
| m: usize, | ||
| a: [Mint; n], | ||
| b: [Mint; m], | ||
| } | ||
|
|
||
| print_oneline(convolution::convolution(&a, &b)); | ||
| } | ||
|
|
||
| fn print_oneline<I: IntoIterator<Item = T>, T: fmt::Display>(values: I) { | ||
| println!( | ||
| "{}", | ||
| values | ||
| .into_iter() | ||
| .map(|v| v.to_string()) | ||
| .collect::<Vec<_>>() | ||
| .join(" "), | ||
| ) | ||
| } |
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,25 @@ | ||
| #[macro_use] | ||
| extern crate input as _; | ||
| #[macro_use] | ||
| extern crate proconio_derive as _; | ||
|
|
||
| use ac_library_rs::fenwicktree::FenwickTree; | ||
|
|
||
| #[allow(clippy::needless_collect)] | ||
| #[fastout] | ||
| fn main() { | ||
| input! { | ||
| n: usize, | ||
| q: usize, | ||
| r#as: [u64; n], | ||
| lrs: [(usize, usize); q], | ||
| } | ||
|
|
||
| let mut fenwick = FenwickTree::new(n, 0); | ||
| for (i, a) in r#as.into_iter().enumerate() { | ||
| fenwick.add(i, a); | ||
| } | ||
| for (l, r) in lrs { | ||
| println!("{}", fenwick.sum(l, r)); | ||
| } | ||
| } |
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,17 @@ | ||
| #[macro_use] | ||
| extern crate input as _; | ||
| #[macro_use] | ||
| extern crate proconio_derive as _; | ||
|
|
||
| use ac_library_rs::math; | ||
|
|
||
| #[fastout] | ||
| fn main() { | ||
| input! { | ||
| nmabs: [(i64, i64, i64, i64)], | ||
| } | ||
|
|
||
| for (n, m, a, b) in nmabs { | ||
| println!("{}", math::floor_sum(n, m, a, b)); | ||
| } | ||
| } |
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,22 @@ | ||
| #[macro_use] | ||
| extern crate input as _; | ||
|
|
||
| use ac_library_rs::dsu::Dsu; | ||
|
|
||
| fn main() { | ||
| input! { | ||
| n: usize, | ||
| queries: [(u8, usize, usize)], | ||
| } | ||
|
|
||
| let mut dsu = Dsu::new(n); | ||
| for (kind, u, v) in queries { | ||
| match kind { | ||
| 0 => { | ||
| dsu.merge(u, v); | ||
| } | ||
| 1 => println!("{}", u8::from(dsu.same(u, v))), | ||
| _ => unreachable!(), | ||
| } | ||
| } | ||
| } |
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.