#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } template class Compress{ public: vector data; int offset; Compress(vector data_, int offset=0): offset(offset){ data = data_; sort(begin(data), end(data)); data.erase(unique(begin(data), end(data)), end(data)); }; int operator[](T x) { auto p = lower_bound(data.begin(), data.end(), x); assert(x == *p); return offset+(p-data.begin()); } T inv(int x){ return data[x-offset]; } int size(){ return data.size(); } }; int op(int x, int y){ return x+y; } int e(){ return 0; } using Seg = atcoder::segtree; using P = pair; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, k; cin >> n >> k; vector l(n), r(n); vector v; vector

vp(n); for(int i = 0; i < n; i++) { cin >> l[i] >> r[i]; vp[i] = P(l[i], r[i]); v.push_back(l[i]+1); v.push_back(r[i]); } auto cp = Compress(v); int m = cp.size(); sort(vp.begin(), vp.end()); mint neg = 1; Seg seg(m); for(auto [l, r]: vp){ int cnt = seg.prod(cp[l+1], m); if(cnt >= k) neg = 0; else neg *= k-cnt; seg.set(cp[r], seg.get(cp[r])+1); } mint ans = mint(k).pow(n)-neg; cout << ans << endl; }