답안 #739632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
739632 2023-05-10T20:37:53 Z danikoynov Abracadabra (CEOI22_abracadabra) C++14
0 / 100
3000 ms 24396 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 2e5 + 10, maxq = 1e6 + 10;

int n, q, a[maxn], ans[maxq];
vector < pair < int, int > > ask[maxn];

void shuffle_array()
{
    deque < int > d1, d2;
    for (int i = 1; i <= n / 2; i ++)
        d1.push_back(a[i]);
    for (int i = n / 2 + 1; i <= n; i ++)
        d2.push_back(a[i]);

    deque < int > res;
    while(!d1.empty() && !d2.empty())
    {
        if (d1.front() < d2.front())
        {
            res.push_back(d1.front());
            d1.pop_front();
        }
        else
        {
            res.push_back(d2.front());
            d2.pop_front();
        }
    }

    while(!d1.empty())
    {
            res.push_back(d1.front());
            d1.pop_front();
    }

        while(!d2.empty())
    {
            res.push_back(d2.front());
            d2.pop_front();
    }

    for (int i = 1; i <= n; i ++)
        a[i] = res[i - 1];
}

void smart_shuffle()
{
    vector < pair < int, int > > seg;
    int i = 1;
    while(i <= n)
    {
        int j = i;
        while(j <= n && a[i] >= a[j])
            j ++;
        seg.push_back({i, j - 1});
        i = j;
    }

    pair < int, int > ps;
    for (int i = 0; i < seg.size(); i ++)
    {
        pair < int, int > cur = seg[i];
        if (cur.second == n / 2)
            return;
        if (cur.first <= n / 2 && cur.second > n / 2)
        {
            ps.first = n / 2 + 1;
            ps.second = cur.second;
            seg[i].second = n / 2;
        }
    }

    for (int i = 0; i < seg.size(); i ++)
    {
        if (a[seg[i].first] > a[ps.first])
        {
            seg.insert(seg.begin() + i, ps);
            break;
        }
    }


    vector < int > val;
    for (pair < int, int > cur : seg)
    {
        for (int i = cur.first; i <= cur.second; i ++)
            val.push_back(a[i]);
    }    if (val.size() != n)
        while(true);
    for (int i = 1; i <= n; i ++)
        a[i] = val[i - 1];

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

    for (int i = 1; i <= q; i ++)
    {
        int t, v;
        cin >> t >> v;
        t = min(t, n);
        if (t == 0)
            ans[i] = a[v];
        else
        ask[t].push_back({v, i});
    }

    shuffle_array();
    for (int f = 1; f <= n; f ++)
    {
        for (pair < int, int > cur : ask[f])
        {
            ans[cur.second] = a[cur.first];
        }

        /**for (int i = 1; i <= n; i ++)
            cout << a[i] << " ";
        cout << endl;*/
        smart_shuffle();
    }

    for (int i = 1; i <= q; i ++)
        cout << ans[i] << endl;
}

int main()
{
    solve();
    return 0;
}

Compilation message

Main.cpp: In function 'void smart_shuffle()':
Main.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for (int i = 0; i < seg.size(); i ++)
      |                     ~~^~~~~~~~~~~~
Main.cpp:93:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for (int i = 0; i < seg.size(); i ++)
      |                     ~~^~~~~~~~~~~~
Main.cpp:108:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  108 |     }    if (val.size() != n)
      |              ~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 506 ms 23080 KB Output is correct
2 Correct 490 ms 21720 KB Output is correct
3 Correct 472 ms 21324 KB Output is correct
4 Correct 392 ms 20820 KB Output is correct
5 Correct 449 ms 23296 KB Output is correct
6 Correct 404 ms 24052 KB Output is correct
7 Incorrect 448 ms 24396 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3075 ms 15752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3035 ms 8944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 506 ms 23080 KB Output is correct
2 Correct 490 ms 21720 KB Output is correct
3 Correct 472 ms 21324 KB Output is correct
4 Correct 392 ms 20820 KB Output is correct
5 Correct 449 ms 23296 KB Output is correct
6 Correct 404 ms 24052 KB Output is correct
7 Incorrect 448 ms 24396 KB Output isn't correct
8 Halted 0 ms 0 KB -