1 条题解

  • 1
    @ 2025-8-11 10:03:42
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    int a[10000005], n, k, x, m;
    void quick_sort(int l, int r) {
        if (l >= r) {
            return;
        }
        int p1 = l, p2 = r;
        swap(a[l], a[rand() % (r - l + 1) + l]);
        int pivot = a[l];
        while (p1 < p2) {
            while (a[p2] >= pivot && p1 < p2) {
                p2--;
            }
            while (a[p1] <= pivot && p1 < p2) {
                p1++;
            }
            if (p1 < p2) {
                swap(a[p1], a[p2]);
            }
        }
        swap(a[l], a[p1]);
        quick_sort(l,p1-1);
        quick_sort(p1+1,r);
    }
    int main() {
        freopen("kth.in", "r", stdin);
        freopen("kth.out", "w", stdout);
        srand(time(NULL));
        cin >> n >> k;
        cin >> a[0] >> x >> m;
        for (int i = 1; i < n; i++) {
            a[i] = (long long)a[i - 1] * x % m;
        }
        quick_sort(0, n - 1);
        cout << a[k - 1] << endl;
        return 0;
    }
    
    

    信息

    ID
    416
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    (无)
    递交数
    89
    已通过
    38
    上传者