fn read() -> (Vec, Vec>) { let mut s = String::new(); use std::io::Read; std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let mut next = || it.next().unwrap().parse::().unwrap(); let n = next(); let q = next(); let a = (0..n).map(|_| next() as u32).collect::>(); let ask = (0..q) .map(|_| { let m = next(); (0..m).map(|_| next()).collect::>() }) .collect::>(); (a, ask) } fn add(base: &mut Vec, mut v: u32) { for b in base.iter() { v = v.min(v ^ *b); } if v > 0 { base.push(v); } } fn main() { let (a, ask) = read(); let n = a.len(); let q = ask.len(); let mut query = vec![]; for (i, mut ask) in ask.into_iter().enumerate() { ask.insert(0, 0); ask.push(a.len()); for a in ask.windows(2) { let (l, r) = (a[0], a[1]); query.push((l, r, i)); } } const MOD: u64 = 1_000_000_007; let mut pow = vec![1; n + 1]; for i in 1..=n { pow[i] = 2 * pow[i - 1] % MOD; } let mut ans = vec![1; q]; let mut memo = vec![vec![]; n]; let mut dfs = vec![(0, n, query)]; while let Some((l, r, ask)) = dfs.pop() { if l + 1 == r { if a[l] == 0 { for (_, _, k) in ask { ans[k] = 2 * ans[k] % MOD; } } continue; } let m = (l + r) / 2; let mut x = vec![]; let mut y = vec![]; let mut c = vec![]; for p in ask { if p.1 <= m { x.push(p); } else if m <= p.0 { y.push(p); } else { c.push(p); } } dfs.push((l, m, x)); dfs.push((m, r, y)); c.sort_by_key(|p| p.0); let mut base = vec![]; for i in m..r { add(&mut base, a[i]); memo[i] = base.clone(); } let mut base = vec![]; for i in (l..m).rev() { add(&mut base, a[i]); while c.last().map_or(false, |p| p.0 == i) { let (_, r, k) = c.pop().unwrap(); let mut base = base.clone(); for v in memo[r - 1].iter() { add(&mut base, *v); } ans[k] = ans[k] * pow[r - i - base.len()] % MOD; } } memo[m..r].iter_mut().for_each(|p| p.clear()); } use std::io::Write; let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); for a in ans { writeln!(out, "{}", a).ok(); } }