#![allow(unused_imports)] use {std::cmp::*, std::collections::*, std::io::Write, std::ops::*}; #[allow(unused_macros)] macro_rules !dbg {($($e :expr ) ,*) =>{#[cfg (debug_assertions ) ] $({let (e ,mut err ) =(stringify !($e ) ,std ::io ::stderr () ) ;writeln !(err ,"{} = {:?}" ,e ,$e ) .unwrap () } ) *} ;} #[allow(unused_macros)] macro_rules !min {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::min ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::min ($a ,min !($($rest ) ,+) ) } } ;} #[allow(unused_macros)] macro_rules !chmin {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_min =min !($($cmps ) ,+) ;if $base >cmp_min {$base =cmp_min ;true } else {false } } } ;} #[allow(unused_macros)] macro_rules !max {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::max ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::max ($a ,max !($($rest ) ,+) ) } } ;} #[allow(unused_macros)] macro_rules !chmax {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_max =max !($($cmps ) ,+) ;if $base { it: SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next(&mut self) -> T { match self.it.next().unwrap().parse::() { Ok(v) => v, _ => panic!("Scanner error"), } } pub fn next_chars(&mut self) -> Vec { self.next::().chars().collect() } pub fn next_vec(&mut self, len: usize) -> Vec { (0..len).map(|_| self.next()).collect() } } pub fn read_string() -> String { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s } } fn main() { let sc = scanner::read_string(); let mut sc = scanner::Scanner::new(&sc); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); let n: usize = sc.next(); let q: usize = sc.next(); let a: Vec = sc.next_vec(n); let s: String = sc.next(); let s: Vec = s.chars().map(|c| if c == '1' { 1 } else { 0 }).collect(); let t: Vec = sc.next_vec(q); let mut score = vec![vec![0; 2]; 32]; for i in 0..32 { let mut b1 = 1; let mut b2 = 0; for j in 0..n { if s[j] == 0 { if (a[j] >> i) & 1 == 0 { if b1 == 1 { score[i][0] += 1usize << i; b1 = 0; } if b2 == 1 { score[i][1] += 1usize << i; b2 = 0; } } } else { if (a[j] >> i) & 1 == 1 { if b1 == 0 { score[i][0] += 1usize << i; b1 = 1; } if b2 == 0 { score[i][1] += 1usize << i; b2 = 1; } } } } } for &t in t.iter() { let mut ans = 0; for i in 0..32 { if (t >> i) & 1 == 1 { ans += score[i][0]; } else { ans += score[i][1]; } } writeln!(out, "{}", ans).unwrap(); } }