use std::io::Read; fn main() { let mut all_data = String::new(); std::io::stdin().read_to_string(&mut all_data).ok(); let all_data: Vec<&str> = all_data.trim().split('\n').map(|s| s.trim()).collect(); let n: usize = all_data.iter().next().unwrap().split_whitespace().next().unwrap().parse().unwrap(); let a: Vec = all_data.iter().skip(1).next().unwrap().split_whitespace().map(|s| s.parse().unwrap()).collect(); let q: usize = all_data.iter().skip(2).next().unwrap().split_whitespace().next().unwrap().parse().unwrap(); let lrs: Vec<(usize, usize)> = all_data.iter().skip(3).take(q) .map(|s| { let temp: Vec = s.split_whitespace().map(|t| t.parse().unwrap()).collect(); (temp[0], temp[1]) }) .collect(); let mut ascs: Vec = vec![-1; n]; let mut descs: Vec = vec![-1; n]; for i in 0..n { let idx: isize = i as isize; if i == 0 { if n == 1 { ascs[0] = 0; descs[0] = 0; } } else { if a[i-1] <= a[i] { if ascs[i-1] < 0 { ascs[i-1] = idx-1; } ascs[i] = ascs[i-1]; } if a[i-1] >= a[i] { if descs[i-1] < 0 { descs[i-1] = idx - 1; } descs[i] = descs[i-1]; } } } for lr in lrs { println!( "{} {}" , if ascs[lr.0] >= 0 && ascs[lr.0] == ascs[lr.1] { 1 } else { 0 } , if descs[lr.0] >= 0 && descs[lr.0] == descs[lr.1] { 1 } else { 0 } ); } }