114352024-09-20 14:27:32RRoliSorozat generáláscpp17Accepted 50/5026ms7800 KiB
#include <bits/stdc++.h>
using namespace std;

long long tizh(int n) {
    int t = 1;
    for(int i = 1; i <= n; i++) t *= 10;
    return t;
}

long long n, v[1000001], aux[1000001], x, a, b, m, k, hely[1000001], c, lntav;

void msort(int e1, int u2) {
    int u1 = (e1+u2)/2, e2 = u1+1;
    if(e1 != u1) msort(e1, u1);
    if(e2 != u2) msort(e2, u2);
    int l = e1, r = e2, p = e1;
    while(l <= u1 or r <= u2) {
        if((v[l] <= v[r] && l <= u1) || r > u2) {
            aux[p] = v[l];
            l++;
        } else {
            aux[p] = v[r];
            r++;
        }
        p++;
    }
    for(int i = e1; i <= u2; i++) v[i] = aux[i];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    //ifstream f("be.in");
    cin >> m >> x >> a >> b >> n >> k;

    for(int i = 1; i <= n; i++) {
        x = x*a + b + 1000000000000;
        x = x % tizh(3*m);
        x /= tizh(m);
        v[i] = x;
        if(hely[v[i]] != 0) lntav = max(lntav, i-hely[v[i]]);
        hely[v[i]] = i;
    }
    cout << lntav << '\n';
    msort(1, n);
    cout << v[n-k+1];

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms528 KiB
2Accepted0/023ms5644 KiB
3Accepted2/23ms456 KiB
4Accepted2/23ms528 KiB
5Accepted2/23ms760 KiB
6Accepted2/23ms488 KiB
7Accepted2/23ms760 KiB
8Accepted4/44ms488 KiB
9Accepted4/44ms888 KiB
10Accepted4/49ms1308 KiB
11Accepted4/48ms1160 KiB
12Accepted4/413ms1512 KiB
13Accepted4/420ms6888 KiB
14Accepted4/421ms6888 KiB
15Accepted4/419ms6248 KiB
16Accepted4/424ms7204 KiB
17Accepted4/426ms7800 KiB