Submission #668966

# Submission time Handle Problem Language Result Execution time Memory
668966 2022-12-05T09:51:39 Z boris_mihov Abracadabra (CEOI22_abracadabra) C++17
0 / 100
3000 ms 27616 KB
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>

typedef long long llong;
const int MAXQ = 1000000 + 10;
const int MAXN = 200000 + 10;
const int INF = 1e9 + 1;

struct Query
{
    int idx;
    int pos;
    int time;

    inline friend bool operator < (const Query &a, const Query &b)
    {
        return a.time < b.time || (a.time == b.time && a.idx < b.idx);
    }
};

int n, q;
int a[MAXN];
int b[MAXN];
Query queries[MAXQ];
int ans[MAXQ];

void solve()
{
    int qPtr = 1;
    std::sort(queries + 1, queries + 1 + q);
    while (qPtr <= n && queries[qPtr].time == 0)
    {
        ans[queries[qPtr].idx] = a[queries[qPtr].pos];
        qPtr++;
    } 

    for (int shuffle = 1 ; shuffle <= 2*n ; ++shuffle)
    {
        int lPtr = 1, rPtr = n/2 + 1, ptr = 1;
        while (lPtr <= n/2 || rPtr <= n)
        {
            if (lPtr == n/2 + 1)
            {
                b[ptr++] = a[rPtr++];
                continue;
            }

            if (rPtr == n + 1)
            {
                b[ptr++] = a[lPtr++];
                continue;
            }

            if (a[lPtr] < a[rPtr])
            {
                b[ptr++] = a[lPtr++];
                continue;
            } else
            {
                b[ptr++] = a[rPtr++];
                continue;
            }
        }

        bool areEqual = true;
        for (int i = 1 ; i <= n ; ++i)
        {
            areEqual &= (a[i] == b[i]);
            a[i] = b[i];
        }

        if (areEqual) break;
        while (qPtr <= n && queries[qPtr].time == shuffle)
        {
            ans[queries[qPtr].idx] = a[queries[qPtr].pos];
            qPtr++;
        }
    }

    while (qPtr <= n) 
    {
        ans[queries[qPtr].idx] = a[queries[qPtr].pos];
        qPtr++;
    }

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

void read()
{
    std::cin >> n >> q;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i];
    }

    for (int i = 1 ; i <= q ; ++i)
    {
        std::cin >> queries[i].time >> queries[i].pos;
        queries[i].idx = i;
    }
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 285 ms 21360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3007 ms 27616 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 4624 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 285 ms 21360 KB Output isn't correct
2 Halted 0 ms 0 KB -