#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair P; typedef pair PP; const ll MOD=998244353; const double PI=acos(-1); //xのy乗 ll mod_pow(ll x,ll y,ll mod){ ll power=x; ll ret = 1; while(y>0){ if(y&1){ ret = ret*power%mod; } power = power*power%mod; y = y>>1; } return ret; } /* struct combination{ typedef long long ll; std::vector fact,ifact; combination(ll n): fact(n+1),ifact(n+1){ fact[0]=1;//0!=1通り for(ll i=1;i<=n;i++) fact[i] = fact[i-1]*i%MOD; //ifact[n] = fact[n].inv(); // n!の逆元がifact[n] ifact[n] = mod_pow(fact[n],MOD-2,MOD);// n!を(mod-2)乗した後でmodであまりをとった for(ll i=n;i>=1;i--) ifact[i-1] = ifact[i]*i%MOD; } ll operator()(ll n,ll k){ if(k<0 || k>n) return 0; // n!/( k!*(n-k)! ) return (fact[n]*ifact[k])%MOD * ifact[n-k]%MOD; } }; combination comb(2*100000); */ template struct binary_indexed_tree{ int N; vector bit; binary_indexed_tree(int n):N(n+1){ bit = vector(n+1,0); N=n; } void add(int x,Type a){ x++;//1から始めるための補正 //for(int i=x; i<=N; i+=(i&-i)) bit[i] = addition(bit[i],a); while(x<=N){ //bit[x] = addition(bit[x],a); bit[x] =bit[x]+a; x += x&-x; } } Type sum(int x){ x++;//1から始まることに注意 Type ret=0; //for(int i=x; i>0; i-=(i&-i)) ret = addition(ret,bit[i]); while(x>0){ ret = ret+bit[x]; x -= x&-x; } return ret; } //[l,r]の範囲 // rはN-1以下 Type get(int l,int r){ if(r>N) return 0;//配列の外へのアクセス if(l>r) return 0;//本来は l<=r となるのでおかしい if(l==0) return sum(r);//[0,r]//ここでoutなわけか else return (sum(r) - sum(l-1)); } }; int main(){ int N,K; cin>>N>>K; vector L(N),R(N); vector

range; for(int i=0;i>L[i]>>R[i]; range.emplace_back(L[i],i); } sort(range.begin(),range.end()); int n=range.size(); ll res=1; ll tot=mod_pow(K,N,MOD);//K^N binary_indexed_tree bit(200000+5); for(int i=0;i