-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
8 changed files
with
256 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,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<u8> = 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: std::str::FromStr>() -> 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); | ||
} |
This file contains 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,6 @@ | ||
b | ||
c | ||
d | ||
e | ||
f | ||
g |
This file contains 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,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<u8> = 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: std::str::FromStr>() -> 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" | ||
}); | ||
} |
This file contains 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,6 @@ | ||
b | ||
c | ||
d | ||
e | ||
f | ||
g |
This file contains 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,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..]); | ||
} |
This file contains 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,6 @@ | ||
b | ||
c | ||
d | ||
e | ||
f | ||
g |
This file contains 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,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::<Vec<_>>() | ||
}; | ||
($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<I, BiOp> { | ||
n: usize, | ||
orign: usize, | ||
dat: Vec<I>, | ||
op: BiOp, | ||
e: I, | ||
} | ||
|
||
impl<I, BiOp> SegTree<I, BiOp> | ||
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<usize>) -> 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); | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,2 +1 @@ | ||
f | ||
g |