// TLE O(NQ) #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using mint = modint998244353; using ll = long long; int main(){ cin.tie(0)->sync_with_stdio(0); int n, Q; cin >> n >> Q; vector A(n + 1); A[0] = 1 << 30; for(int i = 1; i < n + 1; i++) cin >> A[i]; int l, r; while(Q--){ cin >> l >> r; mint ans = 0; for(int i = r; i >= l; i--){ if(i == l || A[i - 1] >= A[i]){ ans += A[i]; break; } ans *= 2; ans += A[i]; } cout << ans.val() << "\n"; } }