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 tmp = vec![0usize; m / w + 2]; 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 { tmp.clear(); tmp.resize(m / w + 2, 0); let q = v / w; let r = v % w; if r == 0 { for (t, bit) in tmp.iter_mut().fuse().skip(q).zip(bit.iter()) { *t = *bit; } } else { for (t, bit) in tmp.iter_mut().fuse().skip(q).zip(bit.iter()) { *t |= *bit << r; } for (t, bit) in tmp.iter_mut().fuse().skip(q + 1).zip(bit.iter()) { *t |= *bit >> (w - r); } } for (bit, tmp) in bit.iter_mut().zip(tmp.iter()) { *bit |= *tmp; } 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(); }