Struct Scanner

Source
pub struct Scanner<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Scanner<'a>

Source

pub fn new(s: &'a str) -> Self

Examples found in repository?
crates/library_checker/src/sample/aplusb.rs (line 6)
4pub fn aplusb(reader: impl Read, mut writer: impl Write) {
5    let s = read_all_unchecked(reader);
6    let mut scanner = Scanner::new(&s);
7    scan!(scanner, a, b);
8    writeln!(writer, "{}", a + b).ok();
9}
More examples
Hide additional examples
crates/aizu_online_judge/src/dpl/dpl_3_c.rs (line 8)
6pub fn dpl_3_c(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, h: [usize; n]);
10    writeln!(writer, "{}", largest_rectangle(&h)).ok();
11}
crates/aizu_online_judge/src/dpl/dpl_1_e.rs (line 8)
6pub fn dpl_1_e(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, s1: Chars, s2: Chars);
10    writeln!(writer, "{}", levenshtein_distance(&s1, &s2)).ok();
11}
crates/library_checker/src/string/zalgorithm.rs (line 8)
6pub fn zalgorithm(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, s: Chars);
10    let z = Zarray::new(&s);
11    iter_print!(writer, @it (0..s.len()).map(|i| z[i]));
12}
13
14#[verify::library_checker("zalgorithm")]
15pub fn zalgorithm_rolling_hash(reader: impl Read, mut writer: impl Write) {
16    let s = read_all_unchecked(reader);
17    let mut scanner = Scanner::new(&s);
18    scan!(scanner, s: Bytes);
19    Mersenne61x1::init(s.len());
20    let h = Mersenne61x1::hash_sequence(s.iter().map(|&c| c as _));
21    let ans = (0..s.len()).map(|i| h.range(..).longest_common_prefix(&h.range(i..)));
22    iter_print!(writer, @it ans);
23}
crates/aizu_online_judge/src/dpl/dpl_3_a.rs (line 8)
6pub fn dpl_3_a(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, h, w, c: [[u8; w]; h]);
10    let res = largest_square(h, w, |i, j| c[i][j] == 0);
11    writeln!(writer, "{}", res).ok();
12}
crates/library_checker/src/sample/many_aplusb.rs (line 6)
4pub fn many_aplusb(reader: impl Read, mut writer: impl Write) {
5    let s = read_all_unchecked(reader);
6    let mut scanner = Scanner::new(&s);
7    scan!(scanner, t);
8    for (a, b) in scanner.iter::<(usize, usize)>().take(t) {
9        writeln!(writer, "{}", a + b).ok();
10    }
11}
Source

pub fn scan<T>(&mut self) -> <T as IterScan>::Output
where T: IterScan,

Examples found in repository?
crates/aizu_online_judge/src/dsl/dsl_2_d.rs (line 12)
6pub fn dsl_2_d(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, q);
10    let mut seg = LazySegmentTree::<RangeMinRangeUpdate<_>>::new(n);
11    for _ in 0..q {
12        match scanner.scan::<usize>() {
13            0 => {
14                scan!(scanner, s, t, x: i32);
15                seg.update(s..t + 1, Some(x));
16            }
17            1 => {
18                scan!(scanner, i);
19                writeln!(writer, "{}", seg.fold(i..i + 1)).ok();
20            }
21            _ => panic!("unknown query"),
22        }
23    }
24}
More examples
Hide additional examples
crates/aizu_online_judge/src/dsl/dsl_2_f.rs (line 12)
6pub fn dsl_2_f(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, q);
10    let mut seg = LazySegmentTree::<RangeMinRangeUpdate<_>>::new(n);
11    for _ in 0..q {
12        match scanner.scan::<usize>() {
13            0 => {
14                scan!(scanner, s, t, x: i32);
15                seg.update(s..t + 1, Some(x));
16            }
17            1 => {
18                scan!(scanner, s, t);
19                writeln!(writer, "{}", seg.fold(s..t + 1)).ok();
20            }
21            _ => panic!("unknown query"),
22        }
23    }
24}
crates/aizu_online_judge/src/dsl/dsl_2_h.rs (line 12)
6pub fn dsl_2_h(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, q);
10    let mut seg = LazySegmentTree::<RangeMinRangeAdd<_>>::from_vec(vec![0; n]);
11    for _ in 0..q {
12        match scanner.scan::<usize>() {
13            0 => {
14                scan!(scanner, s, t, x: i64);
15                seg.update(s..t + 1, x);
16            }
17            1 => {
18                scan!(scanner, s, t);
19                writeln!(writer, "{}", seg.fold(s..t + 1)).ok();
20            }
21            _ => panic!("unknown query"),
22        }
23    }
24}
crates/aizu_online_judge/src/dsl/dsl_2_e.rs (line 12)
6pub fn dsl_2_e(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, q);
10    let mut seg = LazySegmentTree::<RangeSumRangeAdd<_>>::from_vec(vec![(0, 1); n]);
11    for _ in 0..q {
12        match scanner.scan::<usize>() {
13            0 => {
14                scan!(scanner, s, t, x: u64);
15                seg.update(s - 1..t, x);
16            }
17            1 => {
18                scan!(scanner, i);
19                writeln!(writer, "{}", seg.fold(i - 1..i).0).ok();
20            }
21            _ => panic!("unknown query"),
22        }
23    }
24}
crates/aizu_online_judge/src/dsl/dsl_2_g.rs (line 12)
6pub fn dsl_2_g(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, q);
10    let mut seg = LazySegmentTree::<RangeSumRangeAdd<_>>::from_vec(vec![(0, 1); n]);
11    for _ in 0..q {
12        match scanner.scan::<usize>() {
13            0 => {
14                scan!(scanner, s, t, x: u64);
15                seg.update(s - 1..t, x);
16            }
17            1 => {
18                scan!(scanner, s, t);
19                writeln!(writer, "{}", seg.fold(s - 1..t).0).ok();
20            }
21            _ => panic!("unknown query"),
22        }
23    }
24}
crates/aizu_online_judge/src/dsl/dsl_2_i.rs (line 12)
6pub fn dsl_2_i(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, q);
10    let mut seg = LazySegmentTree::<RangeSumRangeUpdate<_>>::from_vec(vec![(0, 1); n]);
11    for _ in 0..q {
12        match scanner.scan::<usize>() {
13            0 => {
14                scan!(scanner, s, t, x: i64);
15                seg.update(s..t + 1, Some(x));
16            }
17            1 => {
18                scan!(scanner, s, t);
19                writeln!(writer, "{}", seg.fold(s..t + 1).0).ok();
20            }
21            _ => panic!("unknown query"),
22        }
23    }
24}
Source

pub fn mscan<T>(&mut self, marker: T) -> <T as MarkedIterScan>::Output
where T: MarkedIterScan,

Source

pub fn scan_vec<T>(&mut self, size: usize) -> Vec<<T as IterScan>::Output>
where T: IterScan,

Source

pub fn iter<'b, T>(&'b mut self) -> ScannerIter<'a, 'b, T>
where T: IterScan,

Examples found in repository?
crates/library_checker/src/sample/many_aplusb.rs (line 8)
4pub fn many_aplusb(reader: impl Read, mut writer: impl Write) {
5    let s = read_all_unchecked(reader);
6    let mut scanner = Scanner::new(&s);
7    scan!(scanner, t);
8    for (a, b) in scanner.iter::<(usize, usize)>().take(t) {
9        writeln!(writer, "{}", a + b).ok();
10    }
11}
More examples
Hide additional examples
crates/library_checker/src/datastructure/range_kth_smallest.rs (line 11)
6pub fn range_kth_smallest(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, q, a: [usize; n]);
10    let wm = WaveletMatrix::new(a, 30);
11    for (l, r, k) in scanner.iter::<(usize, usize, usize)>().take(q) {
12        writeln!(writer, "{}", wm.quantile(l..r, k)).ok();
13    }
14}
crates/library_checker/src/math/factorize.rs (line 10)
6pub fn factorize(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, q);
10    for a in scanner.iter::<u64>().take(q) {
11        let x = prime_factors_flatten(a);
12        write!(writer, "{}", x.len()).ok();
13        for x in x.into_iter() {
14            write!(writer, " {}", x).ok();
15        }
16        writeln!(writer).ok();
17    }
18}
crates/aizu_online_judge/src/grl/grl_3_c.rs (line 12)
6pub fn grl_3_c(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, vs, es, (graph, _): @DirectedGraphScanner::<usize, ()>::new(vs, es));
10    let scc = StronglyConnectedComponent::new(&graph);
11    scan!(scanner, q);
12    for (u, v) in scanner.iter::<(usize, usize)>().take(q) {
13        writeln!(writer, "{}", (scc[u] == scc[v]) as u32).ok();
14    }
15}
crates/library_checker/src/graph/lca.rs (line 17)
9pub fn lca_euler_tour(reader: impl Read, mut writer: impl Write) {
10    let s = read_all_unchecked(reader);
11    let mut scanner = Scanner::new(&s);
12    scan!(scanner, n, q, p: [usize]);
13    let edges = p.take(n - 1).enumerate().map(|(i, p)| (i + 1, p)).collect();
14    let graph = UndirectedSparseGraph::from_edges(n, edges);
15    let euler = EulerTourForRichVertex::new(0, &graph);
16    let lca = euler.gen_lca::<LcaMonoidDefaultId>();
17    for (u, v) in scanner.iter::<(usize, usize)>().take(q) {
18        writeln!(writer, "{}", lca.lca(u, v)).ok();
19    }
20}
21
22#[verify::library_checker("lca")]
23pub fn lca_hld(reader: impl Read, mut writer: impl Write) {
24    let s = read_all_unchecked(reader);
25    let mut scanner = Scanner::new(&s);
26    scan!(scanner, n, q, p: [usize]);
27    let edges = p.take(n - 1).enumerate().map(|(i, p)| (i + 1, p)).collect();
28    let mut graph = UndirectedSparseGraph::from_edges(n, edges);
29    let hld = HeavyLightDecomposition::new(0, &mut graph);
30    for (u, v) in scanner.iter::<(usize, usize)>().take(q) {
31        writeln!(writer, "{}", hld.lca(u, v)).ok();
32    }
33}
crates/library_checker/src/datastructure/line_add_get_min.rs (line 11)
6pub fn line_add_get_min(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, q);
10    let mut cht = LineSet::new();
11    for (a, b) in scanner.iter::<(i64, i64)>().take(n) {
12        cht.insert(a, b);
13    }
14    for _ in 0..q {
15        scan!(scanner, ty);
16        if ty == 0 {
17            scan!(scanner, a: i64, b: i64);
18            cht.insert(a, b);
19        } else {
20            scan!(scanner, q: i64);
21            writeln!(writer, "{}", cht.query_min(q).unwrap()).ok();
22        }
23    }
24}

Trait Implementations§

Source§

impl<'a> Clone for Scanner<'a>

Source§

fn clone(&self) -> Scanner<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Scanner<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Scanner<'a>

§

impl<'a> RefUnwindSafe for Scanner<'a>

§

impl<'a> Send for Scanner<'a>

§

impl<'a> Sync for Scanner<'a>

§

impl<'a> Unpin for Scanner<'a>

§

impl<'a> UnwindSafe for Scanner<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.