#include #include using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; struct t3 { int left, right, index; }; bool sec_sort(t3 a, t3 b) { return a.right < b.right; } //defmodfact const int COMinitMAX = 300000; mint fact[COMinitMAX+1], factinv[COMinitMAX+1]; void modfact(){ fact[0] = 1; for (int i=1; i<=COMinitMAX; i++){ fact[i] = fact[i-1] * i; } factinv[COMinitMAX] = fact[COMinitMAX].inv(); for (int i=COMinitMAX-1; i>=0; i--){ factinv[i] = factinv[i+1] * (i+1); } } mint cmb(int a, int b){ if (a> mo(sep+1, vector(0)); int t; cin >> t; int n, m; t3 f; for(int i=0; i> n >> m; f.left = n-1; f.right = m-1; f.index = i; mo[(n-1)/sep].push_back(f); } int l = 0; int r = 0; int tl, tr; tl = 0; tr = 0; mint nowans = 1; vector ans(t); mint inv2 = mint(2).inv(); for(int i=0; i=tr; k--) { nowans -= cmb(l, k+1); } r = min(r, tr); for(int k=l; k= 1) nowans = nowans * 2 - cmb(k, r); else nowans = nowans; } for(int k=l-1; k>=tl; k--) { if (r >= 1) nowans = (nowans + cmb(k, r)) * inv2; else nowans = nowans; } l = tl; for(int k=r; k