#include #include using namespace std; using namespace atcoder; using mint = modint998244353; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, q; cin >> n >> q; vector a(n); for (auto &&x : a) { cin >> x; } vector last(n); for (int i = 1; i < n; i++) { if (a.at(i) > a.at(i - 1)) { last.at(i) = last.at(i - 1); } else { last.at(i) = i; } } const mint half = mint(1) / 2; vector s(n + 1), pow_half(n + 1); mint mul = 1; pow_half.at(0) = 1; for (int i = 0; i < n; i++) { s.at(i + 1) = s.at(i) + mul * a.at(i); mul += mul; pow_half.at(i + 1) = pow_half.at(i) * half; } for (int i = 0; i < q; i++) { int l, r; cin >> l >> r; l--; r--; l = max(l, last.at(r)); cout << ((s.at(r + 1) - s.at(l + 1)) * pow_half.at(l + 1) + a.at(l)) .val() << '\n'; } return 0; }