結果
問題 | No.1439 Let's Compare!!!! |
ユーザー | akakimidori |
提出日時 | 2021-03-26 21:38:49 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 73 ms / 2,000 ms |
コード長 | 4,443 bytes |
コンパイル時間 | 16,860 ms |
コンパイル使用メモリ | 380,384 KB |
実行使用メモリ | 19,564 KB |
最終ジャッジ日時 | 2024-05-06 22:16:36 |
合計ジャッジ時間 | 19,326 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 73 ms
18,752 KB |
testcase_11 | AC | 69 ms
18,816 KB |
testcase_12 | AC | 68 ms
18,688 KB |
testcase_13 | AC | 73 ms
18,892 KB |
testcase_14 | AC | 72 ms
18,764 KB |
testcase_15 | AC | 70 ms
19,564 KB |
testcase_16 | AC | 72 ms
19,440 KB |
testcase_17 | AC | 72 ms
19,436 KB |
testcase_18 | AC | 65 ms
18,432 KB |
ソースコード
// ---------- begin SegmentTree Point update Range query ---------- mod segment_tree { pub struct PURQ<T, F> { size: usize, data: Vec<T>, e: T, op: F, } #[allow(dead_code)] impl<T, F> PURQ<T, F> where T: Clone, F: Fn(&T, &T) -> T, { pub fn new(size: usize, e: T, op: F) -> PURQ<T, F> { let size = size.next_power_of_two(); PURQ { size, data: vec![e.clone(); 2 * size], e: e, op: op, } } pub fn update(&mut self, x: usize, v: T) { assert!(x < self.size); let mut x = x + self.size; let data = &mut self.data; data[x] = v; x >>= 1; while x > 0 { data[x] = (self.op)(&data[2 * x], &data[2 * x + 1]); x >>= 1; } } pub fn update_tmp(&mut self, x: usize, v: T) { assert!(x < self.size); self.data[x + self.size] = v; } pub fn update_all(&mut self) { let data = &mut self.data; for k in (1..self.size).rev() { data[k] = (self.op)(&data[2 * k], &data[2 * k + 1]); } } pub fn find(&self, l: usize, r: usize) -> T { assert!(l <= r && r <= self.size); if l == r { return self.e.clone(); } let mut p = self.e.clone(); let mut q = self.e.clone(); let mut l = l + self.size; let mut r = r + self.size; let data = &self.data; while l < r { if l & 1 == 1 { p = (self.op)(&p, &data[l]); l += 1; } if r & 1 == 1 { r -= 1; q = (self.op)(&data[r], &q); } l >>= 1; r >>= 1; } (self.op)(&p, &q) } } } // ---------- end SegmentTree Point update Range query ---------- // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- use std::io::Write; fn run() { input! { n: usize, s: bytes, t: bytes, q: usize, ask: [(bytes, usize1, u8); q], } use std::cmp::*; let mut seg = segment_tree::PURQ::new(n, Ordering::Equal, |a, b| a.then(*b)); for (i, (s, t)) in s.iter().zip(t.iter()).enumerate() { seg.update(i, s.cmp(t)); } seg.update_all(); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); let mut s = s; let mut t = t; for (op, x, y) in ask { if op[0] == b'S' { s[x] = y + b'0'; } else { t[x] = y + b'0'; } seg.update(x, s[x].cmp(&t[x])); let ans = match seg.find(0, n) { Ordering::Equal => '=', Ordering::Less => '<', _ => '>', }; writeln!(out, "{}", ans).ok(); } } fn main() { run(); }