use std::io; const MOD: i64 = 998244353; const HALF: i64 = (MOD + 1) / 2; fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); let v: Vec<_> = s.split_whitespace().collect(); let n: usize = v[0].trim().parse().unwrap(); let q: usize = v[1].trim().parse().unwrap(); let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); let v: Vec<_> = s.split_whitespace().collect(); let mut a: Vec = vec![0; n]; for i in 0..n { a[i] = v[i].trim().parse().unwrap(); } let mut l: Vec = vec![0; q]; let mut r: Vec = vec![0; q]; let s = io::read_to_string(io::stdin()).unwrap(); let v: Vec<_> = s.split_whitespace().collect(); for i in 0..q { l[i] = v[2 * i].trim().parse().unwrap(); r[i] = v[2 * i + 1].trim().parse().unwrap(); } let mut last = vec![0; n]; for i in 1..n { if a[i] > a[i - 1] { last[i] = last[i - 1]; } else { last[i] = i; } } let mut a_sum = vec![0; n + 1]; let mut pow_half = vec![1; n + 1]; let mut mul: i64 = 1; for i in 0..n { a_sum[i + 1] = (a_sum[i] + mul * a[i]) % MOD; mul += mul; if mul >= MOD { mul -= MOD; } pow_half[i + 1] = pow_half[i] * HALF % MOD; } for i in 0..q { l[i] -= 1; r[i] -= 1; l[i] = l[i].max(last[r[i]]); println!( "{}", ((a_sum[r[i] + 1] - a_sum[l[i] + 1] + MOD) * pow_half[l[i] + 1] + a[l[i]]) % MOD ); } }