use std::collections::HashMap; fn main() { let stdin = std::io::stdin(); let mut line = String::new(); stdin.read_line(&mut line).unwrap(); let line: Vec<&str> = line.split_whitespace().collect(); let _n = line[0].parse::().unwrap(); let q = line[1].parse::().unwrap(); let mut line = String::new(); stdin.read_line(&mut line).unwrap(); let a: Vec = line .split_whitespace() .map(|s| s.parse::().unwrap()) .collect(); let mut dist: Vec = a.clone(); dist.sort(); let mut count = HashMap::::default(); let mut cum_count: HashMap<_, _> = HashMap::default(); for (i, &pos) in dist.iter().enumerate() { *count.entry(pos).or_insert(0) += 1; cum_count.insert(pos, i + 1); } for _i in 0..q { let mut line = String::new(); stdin.read_line(&mut line).unwrap(); let q: Vec = line .split_whitespace() .map(|s| s.parse::().unwrap()) .collect(); let (x, y) = (q[0], q[1]); let pos_x = a[x - 1]; let pos_y = a[y - 1]; if pos_x <= pos_y { println!("0"); } else { println!( "{}", cum_count.get(&pos_x).unwrap() - count.get(&pos_x).unwrap() - cum_count.get(&pos_y).unwrap() ); } } }