use std::io::Read; use std::io::Write; fn run() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let m: usize = it.next().unwrap().parse().unwrap(); let mut a = vec![(0usize, 0); n]; for a in a.iter_mut() { a.0 = it.next().unwrap().parse().unwrap(); } let q: usize = it.next().unwrap().parse().unwrap(); let mut edge = vec![]; for i in 0..q { let x = it.next().unwrap().parse::().unwrap() - 1; let v: usize = it.next().unwrap().parse().unwrap(); if i > 0 { edge.push((a[x].1, i, a[x].0)); } a[x] = (v, i); } for (a, s) in a { edge.push((s, q, a)); } let w = std::mem::size_of::() * 8; let mut bit = vec![0usize; m / w + 1]; bit[0] = 1; let mut stack = vec![(0, q, edge, bit)]; let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); while let Some((l, r, e, mut bit)) = stack.pop() { let mid = (l + r) / 2; let mut left = vec![]; let mut right = vec![]; for (x, y, v) in e { if x <= l && r <= y { let q = v / w; let r = v % w; if r == 0 { for i in (q..bit.len()).rev() { bit[i] |= bit[i - q]; } } else { for i in ((q + 1)..bit.len()).rev() { let x = bit[i - q - 1]; let y = bit[i - q]; bit[i] |= (x >> (w - r)) | (y << r); } bit[q] |= bit[0] << r; } continue; } if l < mid { left.push((x, y, v)); } if mid < r { right.push((x, y, v)); } } if l + 1 == r { writeln!(out, "{}", (bit[m / w] >> (m % w)) & 1).ok(); } else { stack.push((mid, r, right, bit.clone())); stack.push((l, mid, left, bit)); } } } fn main() { run(); }