Submission #682992

# Submission time Handle Problem Language Result Execution time Memory
682992 2023-01-17T12:34:57 Z nutella Abracadabra (CEOI22_abracadabra) C++17
0 / 100
3000 ms 32160 KB
#include <bits/stdc++.h>

using namespace std;

void riffle_shuffle(vector<int> &a) {
    vector<int> L(a.begin(), a.begin() + a.size() / 2);
    vector<int> R(a.begin() + a.size() / 2, a.end());

    int i = 0, j = 0;
    int n = a.size() / 2;

    while (i < n || j < n) {
        if (i != n && (j == n || L[i] < R[j])) {
            a[j + i] = L[i];
            i += 1;
        } else {
            a[j + i] = R[j];
            j += 1;
        }
    }
}

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

    int n, q;
    cin >> n >> q;

    vector<int> a(n);
    for (int &x : a) {
        cin >> x;
    }

    vector<array<int, 3>> queries(q);
    for (int i = 0; i < q; ++i) {
        cin >> queries[i][0] >> queries[i][1];
        queries[i][2] = i;
    }

    sort(queries.begin(), queries.end());

    vector<int> ans(q, -1);

    int pnt = 0;


    for (int _ = 0; ; ++_) {
        while (pnt < q && queries[pnt][0] == _) {
            ans[queries[pnt][2]] = a[queries[pnt][1] - 1];

            pnt += 1;
        }

        if (pnt == q) {
            break;
        }

        auto prv = a;

        riffle_shuffle(a);

        assert(_ <= n);

        auto count_mx = [&](int l, int r) {
            int mx = 0, cnt = 0;
            for (int i = l; i < r; ++i) {
                if (mx < a[i]) {
                    cnt += 1;
                    mx = a[i];
                }
            }
            return cnt;
        };

        if (_ >= 100) {
            assert(count_mx(0, n / 2) <= 100);
        }

        if (prv == a) {
            while (pnt < q) {
                ans[queries[pnt][2]] = a[queries[pnt][1] - 1];

                pnt += 1;
            }
            break;
        }
    }

    for (int i = 0; i < q; ++i) {
        cout << ans[i] << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 272 ms 32160 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3075 ms 18568 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3039 ms 3532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 272 ms 32160 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -