結果
問題 | No.2308 [Cherry 5th Tune B] もしかして、真? |
ユーザー | tipstar0125 |
提出日時 | 2023-05-22 16:05:58 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 255 ms / 2,000 ms |
コード長 | 8,037 bytes |
コンパイル時間 | 11,545 ms |
コンパイル使用メモリ | 402,412 KB |
実行使用メモリ | 28,784 KB |
最終ジャッジ日時 | 2024-06-01 21:47:09 |
合計ジャッジ時間 | 21,507 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 163 ms
10,060 KB |
testcase_02 | AC | 189 ms
15,364 KB |
testcase_03 | AC | 179 ms
15,740 KB |
testcase_04 | AC | 182 ms
16,748 KB |
testcase_05 | AC | 186 ms
17,540 KB |
testcase_06 | AC | 212 ms
22,724 KB |
testcase_07 | AC | 207 ms
21,536 KB |
testcase_08 | AC | 220 ms
24,272 KB |
testcase_09 | AC | 213 ms
24,264 KB |
testcase_10 | AC | 175 ms
15,912 KB |
testcase_11 | AC | 196 ms
15,520 KB |
testcase_12 | AC | 199 ms
15,520 KB |
testcase_13 | AC | 202 ms
15,392 KB |
testcase_14 | AC | 200 ms
15,392 KB |
testcase_15 | AC | 203 ms
15,524 KB |
testcase_16 | AC | 206 ms
15,388 KB |
testcase_17 | AC | 202 ms
15,392 KB |
testcase_18 | AC | 212 ms
15,392 KB |
testcase_19 | AC | 212 ms
15,396 KB |
testcase_20 | AC | 211 ms
15,524 KB |
testcase_21 | AC | 242 ms
28,672 KB |
testcase_22 | AC | 248 ms
28,668 KB |
testcase_23 | AC | 236 ms
28,656 KB |
testcase_24 | AC | 239 ms
28,700 KB |
testcase_25 | AC | 234 ms
28,784 KB |
testcase_26 | AC | 240 ms
28,772 KB |
testcase_27 | AC | 247 ms
28,736 KB |
testcase_28 | AC | 242 ms
28,664 KB |
testcase_29 | AC | 235 ms
28,676 KB |
testcase_30 | AC | 255 ms
28,708 KB |
testcase_31 | AC | 124 ms
28,640 KB |
testcase_32 | AC | 124 ms
28,644 KB |
testcase_33 | AC | 124 ms
28,676 KB |
testcase_34 | AC | 131 ms
28,780 KB |
testcase_35 | AC | 127 ms
28,700 KB |
testcase_36 | AC | 129 ms
28,724 KB |
testcase_37 | AC | 8 ms
6,940 KB |
testcase_38 | AC | 214 ms
15,516 KB |
ソースコード
#![allow(non_snake_case)] #![allow(unused_imports)] #![allow(unused_macros)] #![allow(clippy::needless_range_loop)] #![allow(clippy::comparison_chain)] #![allow(clippy::nonminimal_bool)] #![allow(clippy::neg_multiply)] #![allow(dead_code)] // use itertools::Itertools; // use superslice::Ext; use std::cmp::Reverse; use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque}; #[derive(Default)] struct Solver {} impl Solver { fn solve(&mut self) { input! { T: usize, } let f = |a: bool, b: bool, e: &String| -> bool { if e.as_str() == "and" { a & b } else if e.as_str() == "or" { a | b } else if e.as_str() == "xor" { a ^ b } else { !a | b } }; for _ in 0..T { input! { N: usize, X: [String; N], Y: [String; N - 1], S: [usize; N - 1] } let mut X: Vec<bool> = X.iter().map(|x| x.as_str() == "True").collect(); // let mut set_u = BinaryIndexedTree::new(N); // set_u.build(&vec![1; N]); // let mut set_v = BinaryIndexedTree::new(N - 1); // set_v.build(&vec![1; N - 1]); let mut set_u = BinaryIndexedTree::new(1); set_u.add(0, 1); for _ in 0..N - 1 { set_u.push(1); } let mut set_v = BinaryIndexedTree::new(0); for _ in 0..N - 1 { set_v.push(1); } let mut ans = true; for &s in &S { let pos_u0 = set_u.lower_bound(s as isize) as usize; let pos_u1 = set_u.lower_bound(s as isize + 1) as usize; let pos_v = set_v.lower_bound(s as isize) as usize; ans = f(X[pos_u0], X[pos_u1], &Y[pos_v]); X[pos_u0] = ans; set_u.add(pos_u1, -1); set_v.add(pos_v, -1); } if ans { println!("True"); } else { println!("False"); } } } } #[derive(Debug, Clone)] struct BinaryIndexedTree { size: usize, data: Vec<isize>, } impl BinaryIndexedTree { fn new(n: usize) -> Self { BinaryIndexedTree { size: n, data: vec![0; n], } } fn lsb(&self, i: usize) -> usize { i & i.wrapping_neg() } fn build(&mut self, v: &[isize]) { assert_eq!(self.size, v.len(), "size not correct!"); self.data = v.to_vec(); for i in 1..=self.size { let lsb = self.lsb(i); if i + lsb <= self.size { self.data[i + lsb - 1] += self.data[i - 1]; } } } fn push(&mut self, mut x: isize) { self.size += 1; let mut d = 1; let k = self.lsb(self.size); while d != k { x += self.data[self.size - d - 1]; d <<= 1; } self.data.push(x); } fn add(&mut self, i: usize, x: isize) { let mut idx = i + 1; while idx <= self.size { self.data[idx - 1] += x; idx += self.lsb(idx); } } // [0, r) fn sum(&self, i: usize) -> isize { let mut ret = 0; let mut idx = i; while idx > 0 { ret += self.data[idx - 1]; idx -= self.lsb(idx); } ret } // [l, r) fn range_sum(&self, l: usize, r: usize) -> isize { self.sum(r) - self.sum(l) } fn lower_bound(&self, x: isize) -> isize { let mut i = 0; let mut k = 1; let mut x = x; while k <= self.size { k <<= 1; } while k > 0 { if i + k <= self.size && self.data[i + k - 1] < x { x -= self.data[i + k - 1]; i += k; } k >>= 1; } if x > 0 { i as isize } else { -1 } } fn upper_bound(&self, x: isize) -> isize { let mut i = 0; let mut k = 1; let mut x = x; while k <= self.size { k <<= 1; } while k > 0 { if i + k <= self.size && self.data[i + k - 1] <= x { x -= self.data[i + k - 1]; i += k; } k >>= 1; } if i < self.size { i as isize } else { -1 } } } #[macro_export] macro_rules! max { ($x: expr) => ($x); ($x: expr, $( $y: expr ),+) => { std::cmp::max($x, max!($( $y ),+)) } } #[macro_export] macro_rules! min { ($x: expr) => ($x); ($x: expr, $( $y: expr ),+) => { std::cmp::min($x, min!($( $y ),+)) } } fn main() { std::thread::Builder::new() .stack_size(128 * 1024 * 1024) .spawn(|| Solver::default().solve()) .unwrap() .join() .unwrap(); } #[macro_export] macro_rules! input { () => {}; (mut $var:ident: $t:tt, $($rest:tt)*) => { let mut $var = __input_inner!($t); input!($($rest)*) }; ($var:ident: $t:tt, $($rest:tt)*) => { let $var = __input_inner!($t); input!($($rest)*) }; (mut $var:ident: $t:tt) => { let mut $var = __input_inner!($t); }; ($var:ident: $t:tt) => { let $var = __input_inner!($t); }; } #[macro_export] macro_rules! __input_inner { (($($t:tt),*)) => { ($(__input_inner!($t)),*) }; ([$t:tt; $n:expr]) => { (0..$n).map(|_| __input_inner!($t)).collect::<Vec<_>>() }; ([$t:tt]) => {{ let n = __input_inner!(usize); (0..n).map(|_| __input_inner!($t)).collect::<Vec<_>>() }}; (chars) => { __input_inner!(String).chars().collect::<Vec<_>>() }; (bytes) => { __input_inner!(String).into_bytes() }; (usize1) => { __input_inner!(usize) - 1 }; ($t:ty) => { $crate::read::<$t>() }; } #[macro_export] macro_rules! println { () => { $crate::write(|w| { use std::io::Write; std::writeln!(w).unwrap() }) }; ($($arg:tt)*) => { $crate::write(|w| { use std::io::Write; std::writeln!(w, $($arg)*).unwrap() }) }; } #[macro_export] macro_rules! print { ($($arg:tt)*) => { $crate::write(|w| { use std::io::Write; std::write!(w, $($arg)*).unwrap() }) }; } #[macro_export] macro_rules! flush { () => { $crate::write(|w| { use std::io::Write; w.flush().unwrap() }) }; } pub fn read<T>() -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, { use std::cell::RefCell; use std::io::*; thread_local! { pub static STDIN: RefCell<StdinLock<'static>> = RefCell::new(stdin().lock()); } STDIN.with(|r| { let mut r = r.borrow_mut(); let mut s = vec![]; loop { let buf = r.fill_buf().unwrap(); if buf.is_empty() { break; } if let Some(i) = buf.iter().position(u8::is_ascii_whitespace) { s.extend_from_slice(&buf[..i]); r.consume(i + 1); if !s.is_empty() { break; } } else { s.extend_from_slice(buf); let n = buf.len(); r.consume(n); } } std::str::from_utf8(&s).unwrap().parse().unwrap() }) } pub fn write<F>(f: F) where F: FnOnce(&mut std::io::BufWriter<std::io::StdoutLock>), { use std::cell::RefCell; use std::io::*; thread_local! { pub static STDOUT: RefCell<BufWriter<StdoutLock<'static>>> = RefCell::new(BufWriter::new(stdout().lock())); } STDOUT.with(|w| f(&mut w.borrow_mut())) }