Submission #677106

# Submission time Handle Problem Language Result Execution time Memory
677106 2023-01-02T09:49:35 Z stanislavpolyn Abracadabra (CEOI22_abracadabra) C++17
10 / 100
3000 ms 26140 KB
#include <bits/stdc++.h>

#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define all(x) (x).begin(), (x).end()
#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()

using namespace std;

mt19937_64 rng(228);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template <typename T>
bool umn(T& a, T b) {
    return a > b ? (a = b, 1) : 0;
}
template <typename T>
bool umx(T& a, T b) {
    return a < b ? (a = b, 1) : 0;
}

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;

const int N = 1e6 + 5;

int n, q;
int a[N];
int ans[N];
ve<array<int, 3>> Q;
int b[N];

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif

    cin >> n >> q;

    fr (i, 1, n) {
        cin >> a[i];
    }

    fr (i, 1, q) {
        int t, pos;
        cin >> t >> pos;
        Q.pb({t, pos, i});
    }
    sort(all(Q));

    bool ok = 0;
    int curT = 0;
    fr (i, 0, sz(Q) - 1) {
        while (!ok && curT < Q[i][0]) {
            int ptr1 = 1;
            int ptr2 = n / 2 + 1;
            int ptr = 1;

            while (ptr1 <= n / 2 || ptr2 <= n) {
                if (ptr1 <= n / 2 && ptr2 <= n) {
                    if (a[ptr1] < a[ptr2]) {
                        b[ptr++] = a[ptr1++];
                    } else {
                        b[ptr++] = a[ptr2++];
                    }
                } else {
                    if (ptr1 <= n / 2) {
                        b[ptr++] = a[ptr1++];
                    } else {
                        b[ptr++] = a[ptr2++];
                    }
                }
            }
            bool same = 1;
            fr (i, 1, n) {
                same &= a[i] == b[i];
                a[i] = b[i];
            }

            if (same) {
                ok = 1;
            }

            curT++;
        }

        ans[Q[i][2]] = a[Q[i][1]];
    }

    fr (i, 1, q) {
        cout << ans[i] << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 329 ms 20032 KB Output is correct
2 Correct 350 ms 25724 KB Output is correct
3 Correct 326 ms 24656 KB Output is correct
4 Correct 334 ms 25228 KB Output is correct
5 Correct 345 ms 26056 KB Output is correct
6 Correct 327 ms 24760 KB Output is correct
7 Correct 343 ms 25284 KB Output is correct
8 Correct 332 ms 24444 KB Output is correct
9 Correct 334 ms 24572 KB Output is correct
10 Correct 330 ms 24860 KB Output is correct
11 Correct 327 ms 24308 KB Output is correct
12 Correct 322 ms 23828 KB Output is correct
13 Correct 343 ms 24092 KB Output is correct
14 Correct 334 ms 26012 KB Output is correct
15 Correct 362 ms 26140 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 328 ms 24816 KB Output is correct
18 Correct 323 ms 24508 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3055 ms 13720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3099 ms 2700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 329 ms 20032 KB Output is correct
2 Correct 350 ms 25724 KB Output is correct
3 Correct 326 ms 24656 KB Output is correct
4 Correct 334 ms 25228 KB Output is correct
5 Correct 345 ms 26056 KB Output is correct
6 Correct 327 ms 24760 KB Output is correct
7 Correct 343 ms 25284 KB Output is correct
8 Correct 332 ms 24444 KB Output is correct
9 Correct 334 ms 24572 KB Output is correct
10 Correct 330 ms 24860 KB Output is correct
11 Correct 327 ms 24308 KB Output is correct
12 Correct 322 ms 23828 KB Output is correct
13 Correct 343 ms 24092 KB Output is correct
14 Correct 334 ms 26012 KB Output is correct
15 Correct 362 ms 26140 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 328 ms 24816 KB Output is correct
18 Correct 323 ms 24508 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Execution timed out 3055 ms 13720 KB Time limit exceeded
22 Halted 0 ms 0 KB -