QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#641149#7407. Program OptimizationKDreamAC ✓306ms14132kbC++201.5kb2024-10-14 18:52:292024-10-14 18:52:29

Judging History

你现在查看的是最新测评结果

  • [2024-10-14 18:52:29]
  • 评测
  • 测评结果:AC
  • 用时:306ms
  • 内存:14132kb
  • [2024-10-14 18:52:29]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 7;
int pre[N], suf[N], a[N];
int n, q, k, s;
int query_mex(const int *a, int l, int r)
{
    return min(pre[l - 1], suf[r + 1]);
}
int simulate(int n, int *a, int q, int k, int s)
{
    std::mt19937 gen;
    gen.seed(s);
    int last = 0;

    while (q--)
    {
        int op = gen() % k;
        int i = (gen() + last) % n;
        i ++;
        if (!op && i > 1)
        {
            std::swap(a[i - 1], a[i]);
            for (int j = i - 1; j <= i; j++)
            {
                pre[j] = min(a[j], pre[j - 1]);
            }
            for (int j = i; j >= i - 1; j--)
            {
                suf[j] = min(a[j], suf[j + 1]);
            }
        }
        else
        {
            int j = gen() % n;
            j ++;
            last ^= query_mex(a, std::min(i, j), std::max(i, j));
        }
    }
    return last;
}
void Z()
{
    cin >> n >> q >> k >> s;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    pre[0] = n;
    for (int i = 1; i <= n; i++)
    {
        pre[i] = min(a[i], pre[i - 1]);
    }
    suf[n + 1] = n;
    for (int i = n; i >= 1; i--)
    {
        suf[i] = min(a[i], suf[i + 1]);
    }
    int ans = simulate(n, a, q, k, s);
    cout << ans;
}

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

    int t = 1;
    // cin >> t;
    while (t--)
    {
        Z();
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7608kb

input:

3 5 1 0
0 1 2

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 216ms
memory: 14128kb

input:

200000 10000000 1 664250662
199997 199996 199994 199993 199992 199991 199990 199989 199988 199987 199986 199984 199983 199981 199979 199978 199977 199976 199975 199974 199973 199970 199969 199968 199966 199965 199964 199963 199962 199961 199960 199958 199957 199956 199955 199953 199952 199951 199948...

output:

106138

result:

ok 1 number(s): "106138"

Test #3:

score: 0
Accepted
time: 306ms
memory: 8432kb

input:

200000 10000000 2 841507843
199999 199998 199997 199996 199995 199994 199993 199992 199991 199990 199989 199988 199987 199986 199985 199984 199983 199982 199981 199980 199979 199978 199977 199976 199975 199974 199973 199972 199971 199970 199969 199968 199967 199966 199965 199964 199963 199962 199961...

output:

218754

result:

ok 1 number(s): "218754"

Test #4:

score: 0
Accepted
time: 306ms
memory: 14132kb

input:

200000 10000000 5 78312093
199986 199976 199970 199943 199942 199931 199916 199909 199908 199907 199894 199882 199870 199869 199852 199849 199848 199833 199821 199805 199800 199795 199771 199755 199753 199739 199738 199736 199734 199728 199720 199715 199712 199705 199699 199697 199695 199694 199685 ...

output:

236570

result:

ok 1 number(s): "236570"

Test #5:

score: 0
Accepted
time: 294ms
memory: 8496kb

input:

200000 10000000 10 603298734
199999 199996 199995 199989 199985 199984 199983 199979 199977 199971 199969 199967 199965 199964 199959 199955 199950 199949 199948 199945 199944 199943 199942 199935 199933 199932 199928 199927 199926 199925 199920 199919 199917 199916 199915 199912 199909 199908 19990...

output:

87050

result:

ok 1 number(s): "87050"

Test #6:

score: 0
Accepted
time: 277ms
memory: 8496kb

input:

200000 10000000 100 356800522
199999 199998 199997 199996 199994 199993 199992 199991 199990 199988 199987 199986 199985 199984 199983 199982 199981 199980 199979 199978 199977 199976 199975 199974 199973 199972 199971 199969 199967 199966 199965 199964 199963 199962 199961 199960 199959 199958 1999...

output:

172112

result:

ok 1 number(s): "172112"

Test #7:

score: 0
Accepted
time: 269ms
memory: 12368kb

input:

200000 10000000 1000 670477491
199999 199998 199996 199994 199992 199991 199990 199989 199987 199985 199983 199981 199979 199978 199977 199975 199974 199972 199971 199970 199969 199965 199964 199962 199960 199959 199957 199956 199954 199953 199950 199949 199945 199944 199943 199940 199939 199938 199...

output:

205440

result:

ok 1 number(s): "205440"

Test #8:

score: 0
Accepted
time: 265ms
memory: 14036kb

input:

200000 10000000 10000 507623558
199998 199997 199996 199995 199994 199993 199991 199988 199986 199985 199984 199983 199981 199980 199978 199976 199974 199973 199972 199971 199970 199969 199968 199967 199966 199964 199963 199962 199961 199955 199954 199953 199952 199951 199950 199949 199948 199947 19...

output:

184512

result:

ok 1 number(s): "184512"

Test #9:

score: 0
Accepted
time: 263ms
memory: 10452kb

input:

200000 10000000 100000 886075807
199995 199992 199990 199980 199978 199975 199973 199972 199969 199961 199956 199951 199946 199944 199942 199940 199935 199934 199928 199927 199925 199912 199911 199907 199906 199905 199900 199899 199896 199894 199887 199884 199880 199878 199877 199874 199872 199871 1...

output:

36720

result:

ok 1 number(s): "36720"

Test #10:

score: 0
Accepted
time: 264ms
memory: 10556kb

input:

200000 10000000 1000000 978245484
199999 199998 199996 199995 199993 199992 199991 199990 199989 199988 199987 199984 199983 199982 199980 199977 199976 199975 199973 199972 199971 199970 199969 199968 199965 199964 199961 199960 199959 199958 199957 199955 199954 199953 199952 199951 199949 199947 ...

output:

260925

result:

ok 1 number(s): "260925"

Extra Test:

score: 0
Extra Test Passed