2 solutions

  • 2
    @ 2026-5-13 17:23:25

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

    #include #include #include #include using namespace std; #define int long long typedef pair<int, int> PII; const int mod = 998244353;

    signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    
    vector<PII> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(), A.end()); // 按左端点排序
    
    priority_queue<int, vector<int>, greater<int>> heap; // 小根堆,存储右端点
    int tem = k;
    int ans = 1;
    
    for (const auto& seg : A) {
        int a = seg.first, b = seg.second;
        // 弹出所有右端点 < a 的线段,释放颜色槽
        while (!heap.empty() && heap.top() < a) {
            heap.pop();
            tem++;
        }
        // 方案数乘以可用槽数
        ans = 1LL * ans * tem % mod;
        // 占用一个槽,更新右端点
        tem--;
        heap.push(b);
    }
    
    cout << ans << endl;
    return 0;
    

    }

  • -2
    @ 2025-5-20 21:45:44

    二分答案 xx,计算每台打印机在xx秒内能打印多少试题,看加起来是否大于等于kk

    那么如何确定最大份数呢?我们可以把每一周期看做每一段,根据时间可以算得有多少段,有多少段就有多少个lil_i

    因为不一定是完整周期,所以我们还要考虑,最后一段不完整的区间,用剩下的时间除以 tit_i,但是需要注意这个结果可能会越界到 wiw_i时间里,也就是说剩下的时间除以tit_i的值最大只能是 lil_i

    #include <bits/stdc++.h>
    
    using i64 = long long;
    
    void Solve() {
        int n, K;
        std::cin >> n >> K;
    
        std::vector<int> t(n), l(n), w(n);
        for (int i = 0; i < n; ++i) {
            std::cin >> t[i] >> l[i] >> w[i];
        }
    
        auto check = [&](i64 mid) -> bool {
            i64 ans = 0;
            for (int i = 0; i < n; ++i) {
                i64 T = 1LL * t[i] * l[i] + w[i];
                ans += mid / T * l[i];
                ans += std::min((mid % T) / t[i], 1LL * l[i]);
                if (ans >= K) {
                    return true;
                }
            }
            return false;
        };
    
        i64 lo = 0, hi = 2e18;
        while (lo < hi) {
            i64 mid = (lo + hi) / 2;
            if (check(mid)) {
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        std::cout << lo << '\n';
    }
    
    int main() {
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(nullptr);
    
        int t = 1;
        for (int ti = 1; ti <= t; ++ti) {
            Solve(); 
        }
    
        return 0;
    }
    
    • 1

    Information

    ID
    1484
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    (None)
    # Submissions
    98
    Accepted
    22
    Uploaded By