#include using namespace std; #include #include using mint=atcoder::static_modint<998244353>; using T=tuple; T f(T s,T t){ if(get<1>(s)==-1)return t; if(get<1>(t)==-1)return s; if(get<1>(s)(t)){ return make_tuple(get<0>(s),get<1>(t),get<2>(s)*get<2>(t),get<3>(s)+get<3>(t)*get<2>(s)); }else{ return make_tuple(~get<0>(t),get<1>(t),get<2>(t),get<3>(t)); } } T id(){ return make_tuple(-1,-1,mint(1),mint(0)); } int main(){ int n,q; cin>>n>>q; vectora(n); vectorv(n); for(int i=0;i>a[i]; v[i]=make_tuple(a[i],a[i],mint(2),mint(a[i])); } atcoder::segtreeseg(v); while(q--){ int l,r; cin>>l>>r; l--; auto [x,y,z,w]=seg.prod(l,r); if(x<0)x=~x; cout<<((w+x)/2).val()<