Submission #68541594


Source Code Expand

use library::utils::input::Input;

fn solve(ip: &mut Input) {
    let (n, m) = ip.pair::<usize,usize>();
    let s = ip.next::<String>().chars().collect::<Vec<_>>();
    let t = ip.next::<String>().chars().collect::<Vec<_>>();

    let mut imos = vec![0i64; n+1];
    
    for _ in 0..m {
        let (l, r) = ip.pair::<usize, usize>();
        imos[l-1] += 1;
        imos[r] -= 1;
    }

    let mut ans = vec![];
    let mut cur = 0;
    
    for (i, imos_i) in imos[..n].iter().enumerate() {
        cur += *imos_i;
        if cur % 2 == 0 {
            ans.push(s[i]);
        } else {
            ans.push(t[i]);
        }
    }
    println!("{}", ans.iter().collect::<String>());

}

fn main() {
    static IS_MULTI_TEST_CASE :bool = false;
    let mut ip = Input::new();

    let t = if IS_MULTI_TEST_CASE {
        ip.next::<usize>()
    } else {
        1
    };

    for _ in 0..t {
        solve(&mut ip);
    }
}


// ===== bundled library =====

pub mod library {
    pub mod utils {
        pub mod input {
            use std::str::{from_utf8, FromStr};
            pub struct Input {
                buf: Vec<u8>,
                pos: usize,
            }
            impl Input {
                pub fn new() -> Self {
                    Self { buf: Vec::new(), pos: 0 }
                }
                pub fn next<T: FromStr>(&mut self) -> T {
                    while self.pos < self.buf.len()
                        && self.buf[self.pos].is_ascii_whitespace()
                    {
                        self.pos += 1;
                    }
                    let start = self.pos;
                    while self.pos < self.buf.len()
                        && !self.buf[self.pos].is_ascii_whitespace()
                    {
                        self.pos += 1;
                    }
                    if start == self.pos {
                        let mut input = String::new();
                        std::io::stdin()
                            .read_line(&mut input)
                            .expect("Failed to read line");
                        self.buf.clear();
                        self.buf.extend(input.as_bytes());
                        self.pos = 0;
                        return self.next();
                    }
                    from_utf8(&self.buf[start..self.pos])
                        .unwrap()
                        .parse::<T>()
                        .ok()
                        .expect(
                            &format!(
                                "Failed to parse input: {}", from_utf8(& self.buf[start
                                ..self.pos]).unwrap()
                            ),
                        )
                }
                #[allow(non_snake_case)]
                pub fn vector<T: FromStr>(&mut self, n: usize) -> Vec<T> {
                    (0..n).map(|_| self.next()).collect()
                }
                pub fn graph(
                    &mut self,
                    n: usize,
                    m: usize,
                    is_one_way: bool,
                ) -> Vec<Vec<usize>> {
                    let mut graph = vec![Vec::new(); n];
                    for _ in 0..m {
                        let (u, v): (usize, usize) = self.pair();
                        graph[u - 1].push(v - 1);
                        if !is_one_way {
                            graph[v - 1].push(u - 1);
                        }
                    }
                    graph
                }
                pub fn weighted_graph<T: Copy + FromStr>(
                    &mut self,
                    n: usize,
                    m: usize,
                    is_one_way: bool,
                    is_one_based: bool,
                ) -> Vec<Vec<(usize, T)>> {
                    let mut graph = vec![Vec::new(); n];
                    for _ in 0..m {
                        let (u, v, w): (usize, usize, T) = self.triple();
                        let u = if is_one_based { u - 1 } else { u };
                        let v = if is_one_based { v - 1 } else { v };
                        graph[u].push((v, w));
                        if !is_one_way {
                            graph[v].push((u, w));
                        }
                    }
                    graph
                }
                pub fn pair<T: FromStr, U: FromStr>(&mut self) -> (T, U) {
                    (self.next(), self.next())
                }
                pub fn triple<T: FromStr, U: FromStr, V: FromStr>(
                    &mut self,
                ) -> (T, U, V) {
                    (self.next(), self.next(), self.next())
                }
            }
        }
    }
}

Submission Info

Submission Time
Task D - Substr Swap
User ardRiriy
Language Rust (rustc 1.70.0)
Score 400
Code Size 4843 Byte
Status AC
Exec Time 54 ms
Memory 12504 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 16
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 2008 KiB
00_sample_01.txt AC 1 ms 2068 KiB
01_test_00.txt AC 1 ms 1912 KiB
01_test_01.txt AC 1 ms 2064 KiB
01_test_02.txt AC 1 ms 1932 KiB
01_test_03.txt AC 1 ms 1924 KiB
01_test_04.txt AC 2 ms 2064 KiB
01_test_05.txt AC 17 ms 4156 KiB
01_test_06.txt AC 24 ms 1796 KiB
01_test_07.txt AC 8 ms 8684 KiB
01_test_08.txt AC 42 ms 11124 KiB
01_test_09.txt AC 44 ms 12504 KiB
01_test_10.txt AC 52 ms 12308 KiB
01_test_11.txt AC 54 ms 12468 KiB
01_test_12.txt AC 36 ms 8656 KiB
01_test_13.txt AC 44 ms 12472 KiB