use std::collections::BTreeMap; fn g() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.split_whitespace().flat_map(str::parse).collect() } fn main() { let q = g()[1]; let a = g(); let mut h = BTreeMap::new(); a.iter().for_each(|&x| *h.entry(x).or_insert(0) += 1); let (mut i, mut d) = (vec![0], vec![0]); for (k, v) in h { d.push(d.last().unwrap() + v); i.push(k); } for _ in 0..q { let z = g(); let x = i.binary_search(&a[z[0] - 1]).map_or(0, |p| d[p - 1]); let y = i.binary_search(&a[z[1] - 1]).map_or(0, |p| d[p]); println!("{}", 0.max(x - y)) } }