QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#202970#7407. Program OptimizationScarlett_boyTL 76ms5208kbC++171.1kb2023-10-06 14:24:132023-10-06 14:24:13

Judging History

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

  • [2023-10-06 14:24:13]
  • 评测
  • 测评结果:TL
  • 用时:76ms
  • 内存:5208kb
  • [2023-10-06 14:24:13]
  • 提交

answer

#include<bits/stdc++.h>

#pragma GCC optimize(3)
typedef long long ll;

using namespace std;
const int N = 2e5 + 50;

const int mod = 1e9 + 7;
int a[N];
int vis[N];

int query_mex(int l, int r) {
    for (int i = 0; i <= 2e5; i++) vis[i] = 0;
    for (int i = l; i <= r; i++) vis[a[i]] = 1;
    int p = 0;
    while (vis[p]) p++;
    return p;
}

int simulate(int n, 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;
        if (!op && i) {
            std::swap(a[i - 1], a[i]);
        } else {
            int j = gen() % n;
            last ^= query_mex(std::min(i, j), std::max(i, j));
        }
    }
    return last;
}

int n, q, k, s;

void solve() {
    cin >> n >> q >> k >> s;
    for (int i = 0; i < n; i++) cin >> a[i];
    cout << simulate(n, q, k, s) << '\n';
}


int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int _ = 1;
//    cin >> _;
    for (int o = 1; o <= _; o++) {
        solve();
    }
    return 0;
}
/*
5 1 4124 23
0 1 2 3 4
0
4
4
3

 */

詳細信息

Test #1:

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

input:

3 5 1 0
0 1 2

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 76ms
memory: 5208kb

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: -100
Time Limit Exceeded

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:


result: