From 40497ca25003a5df0d963e82174bfa42e63d3d0f Mon Sep 17 00:00:00 2001 From: koba-e964 <3303362+koba-e964@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:33:39 +0900 Subject: [PATCH] Add atcoder/abc336/a.rs atcoder/abc336/remain.txt atcoder/abc337/a.rs atcoder/abc337/remain.txt atcoder/abc339/a.rs atcoder/abc339/remain.txt --- atcoder/abc336/a.rs | 33 +++++++++ atcoder/abc336/remain.txt | 6 ++ atcoder/abc337/a.rs | 41 +++++++++++ atcoder/abc337/remain.txt | 6 ++ atcoder/abc339/a.rs | 16 +++++ atcoder/abc339/remain.txt | 6 ++ atcoder/abc343/f.rs | 148 ++++++++++++++++++++++++++++++++++++++ atcoder/abc343/remain.txt | 1 - 8 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 atcoder/abc336/a.rs create mode 100644 atcoder/abc336/remain.txt create mode 100644 atcoder/abc337/a.rs create mode 100644 atcoder/abc337/remain.txt create mode 100644 atcoder/abc339/a.rs create mode 100644 atcoder/abc339/remain.txt create mode 100644 atcoder/abc343/f.rs diff --git a/atcoder/abc336/a.rs b/atcoder/abc336/a.rs new file mode 100644 index 00000000..c56e869b --- /dev/null +++ b/atcoder/abc336/a.rs @@ -0,0 +1,33 @@ +use std::io::Read; + +fn get_word() -> String { + let stdin = std::io::stdin(); + let mut stdin=stdin.lock(); + let mut u8b: [u8; 1] = [0]; + loop { + let mut buf: Vec = Vec::with_capacity(16); + loop { + let res = stdin.read(&mut u8b); + if res.unwrap_or(0) == 0 || u8b[0] <= b' ' { + break; + } else { + buf.push(u8b[0]); + } + } + if buf.len() >= 1 { + let ret = String::from_utf8(buf).unwrap(); + return ret; + } + } +} + +fn get() -> T { get_word().parse().ok().unwrap() } + +fn main() { + let n: i32 = get(); + let mut s = "L".to_string(); + for _ in 0..n { + s.push('o'); + } + println!("{}ng", s); +} diff --git a/atcoder/abc336/remain.txt b/atcoder/abc336/remain.txt new file mode 100644 index 00000000..9fbb6235 --- /dev/null +++ b/atcoder/abc336/remain.txt @@ -0,0 +1,6 @@ +b +c +d +e +f +g diff --git a/atcoder/abc337/a.rs b/atcoder/abc337/a.rs new file mode 100644 index 00000000..b03b7beb --- /dev/null +++ b/atcoder/abc337/a.rs @@ -0,0 +1,41 @@ +use std::io::Read; + +fn get_word() -> String { + let stdin = std::io::stdin(); + let mut stdin=stdin.lock(); + let mut u8b: [u8; 1] = [0]; + loop { + let mut buf: Vec = Vec::with_capacity(16); + loop { + let res = stdin.read(&mut u8b); + if res.unwrap_or(0) == 0 || u8b[0] <= b' ' { + break; + } else { + buf.push(u8b[0]); + } + } + if buf.len() >= 1 { + let ret = String::from_utf8(buf).unwrap(); + return ret; + } + } +} + +fn get() -> T { get_word().parse().ok().unwrap() } + +fn main() { + let n: i32 = get(); + let mut t = 0; + for _ in 0..n { + let x: i32 = get(); + let y: i32 = get(); + t += x - y; + } + println!("{}", if t > 0 { + "Takahashi" + } else if t == 0 { + "Draw" + } else { + "Aoki" + }); +} diff --git a/atcoder/abc337/remain.txt b/atcoder/abc337/remain.txt new file mode 100644 index 00000000..9fbb6235 --- /dev/null +++ b/atcoder/abc337/remain.txt @@ -0,0 +1,6 @@ +b +c +d +e +f +g diff --git a/atcoder/abc339/a.rs b/atcoder/abc339/a.rs new file mode 100644 index 00000000..e52f43c5 --- /dev/null +++ b/atcoder/abc339/a.rs @@ -0,0 +1,16 @@ +fn getline() -> String { + let mut ret = String::new(); + std::io::stdin().read_line(&mut ret).ok().unwrap(); + ret +} + +fn main() { + let s = getline().trim().to_string(); + let mut ans = 0; + for (i, c) in s.bytes().enumerate() { + if c == b'.' { + ans = i; + } + } + println!("{}", &s[ans + 1..]); +} diff --git a/atcoder/abc339/remain.txt b/atcoder/abc339/remain.txt new file mode 100644 index 00000000..9fbb6235 --- /dev/null +++ b/atcoder/abc339/remain.txt @@ -0,0 +1,6 @@ +b +c +d +e +f +g diff --git a/atcoder/abc343/f.rs b/atcoder/abc343/f.rs new file mode 100644 index 00000000..c41389bd --- /dev/null +++ b/atcoder/abc343/f.rs @@ -0,0 +1,148 @@ +use std::io::{Write, BufWriter}; +// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 +macro_rules! input { + ($($r:tt)*) => { + let stdin = std::io::stdin(); + let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); + let mut next = move || -> String{ + bytes.by_ref().map(|r|r.unwrap() as char) + .skip_while(|c|c.is_whitespace()) + .take_while(|c|!c.is_whitespace()) + .collect() + }; + input_inner!{next, $($r)*} + }; +} + +macro_rules! input_inner { + ($next:expr) => {}; + ($next:expr,) => {}; + ($next:expr, $var:ident : $t:tt $($r:tt)*) => { + let $var = read_value!($next, $t); + input_inner!{$next $($r)*} + }; +} + +macro_rules! read_value { + ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; + ($next:expr, [ $t:tt ; $len:expr ]) => { + (0..$len).map(|_| read_value!($next, $t)).collect::>() + }; + ($next:expr, usize1) => (read_value!($next, usize) - 1); + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +// Segment Tree. This data structure is useful for fast folding on intervals of an array +// whose elements are elements of monoid I. Note that constructing this tree requires the identity +// element of I and the operation of I. +// Verified by: yukicoder No. 2220 (https://yukicoder.me/submissions/841554) +struct SegTree { + n: usize, + orign: usize, + dat: Vec, + op: BiOp, + e: I, +} + +impl SegTree + where BiOp: Fn(I, I) -> I, + I: Copy { + pub fn new(n_: usize, op: BiOp, e: I) -> Self { + let mut n = 1; + while n < n_ { n *= 2; } // n is a power of 2 + SegTree {n: n, orign: n_, dat: vec![e; 2 * n - 1], op: op, e: e} + } + // ary[k] <- v + pub fn update(&mut self, idx: usize, v: I) { + debug_assert!(idx < self.orign); + let mut k = idx + self.n - 1; + self.dat[k] = v; + while k > 0 { + k = (k - 1) / 2; + self.dat[k] = (self.op)(self.dat[2 * k + 1], self.dat[2 * k + 2]); + } + } + // [a, b) (half-inclusive) + // http://proc-cpuinfo.fixstars.com/2017/07/optimize-segment-tree/ + #[allow(unused)] + pub fn query(&self, rng: std::ops::Range) -> I { + let (mut a, mut b) = (rng.start, rng.end); + debug_assert!(a <= b); + debug_assert!(b <= self.orign); + let mut left = self.e; + let mut right = self.e; + a += self.n - 1; + b += self.n - 1; + while a < b { + if (a & 1) == 0 { + left = (self.op)(left, self.dat[a]); + } + if (b & 1) == 0 { + right = (self.op)(self.dat[b - 1], right); + } + a = a / 2; + b = (b - 1) / 2; + } + (self.op)(left, right) + } +} + +fn main() { + let out = std::io::stdout(); + let mut out = BufWriter::new(out.lock()); + macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} + input! { + n: usize, q: usize, + a: [i64; n], + qs: [(i32, usize1, usize); q], + } + const INF: i64 = 1 << 50; + fn f((a, ac, b, bc): (i64, usize, i64, usize), (c, cc, d, dc): (i64, usize, i64, usize)) -> (i64, usize, i64, usize) { + let mut x = [a, b, c, d]; + x.sort_unstable(); + let mut sec = -INF-1; + for i in 0..3 { + if x[i] != x[3] { + sec = x[i]; + } + } + let mut fstcount = 0; + let mut seccount = 0; + if a == x[3] { + fstcount += ac; + } + if a == sec { + seccount += ac; + } + if b == x[3] { + fstcount += bc; + } + if b == sec { + seccount += bc; + } + if c == x[3] { + fstcount += cc; + } + if c == sec { + seccount += cc; + } + if d == x[3] { + fstcount += dc; + } + if d == sec { + seccount += dc; + } + (x[3], fstcount, sec, seccount) + } + let mut st = SegTree::new(n, f, (-INF, 0, -INF-1, 0)); + for i in 0..n { + st.update(i, (a[i], 1, -INF, 0)); + } + for (t, x, y) in qs { + if t == 1 { + st.update(x, (y as i64, 1, -INF, 0)); + } else { + puts!("{}\n", st.query(x..y).3); + } + } +} diff --git a/atcoder/abc343/remain.txt b/atcoder/abc343/remain.txt index ab713757..01058d84 100644 --- a/atcoder/abc343/remain.txt +++ b/atcoder/abc343/remain.txt @@ -1,2 +1 @@ -f g