#define MD 998244353 ll@n,@q,c[n+1],p=ll_inf; Mint a[],b[],m; c[0]=ll_inf; rep(i,1,n+1){ ll@x; a[i]=x; if(x<=p){ b[i]=x; c[i]=0; m=1; }else{ b[i]=b[i-1]+x*m; c[i]=c[i-1]+1; m*=2; } p=x; } rep(q){ ll@--l,@r; if(r-l==c[r]-c[l]){ wt((b[r]-b[l])/Mint(2)**c[l+1]+a[l+1]/2); }else{ wt(b[r]); } }