답안 #784660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784660 2023-07-16T11:41:24 Z boris_mihov Abracadabra (CEOI22_abracadabra) C++17
컴파일 오류
0 ms 0 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>

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

int n, q;
llong total;
int a[MAXN];
int b[MAXN];
int output[MAXQ];
std::vector <std::pair <int,int>> v[MAXN];

void riffle()
{
    int pos = 1;
    int lPtr = 1, rPtr = n / 2 + 1;
    while (lPtr < n / 2 + 1 || rPtr < n + 1)
    {
        if (lPtr == n / 2 + 1)
        {
            b[pos++] = a[rPtr++];
            total = std::max(total, pos);
            continue;
        }

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

        if (a[lPtr] < a[rPtr])
        {
            b[pos++] = a[lPtr++];
        } else
        {
            b[pos++] = a[rPtr++];
            total = std::max(total, pos);
        }
    }
    
    for (int i = 1 ; i <= n ; ++i)
    {
        a[i] = b[i];
    }
}

void solve()
{
    int bucketSize = sqrt(n) + 5;
    for (int i = 0 ; i <= bucketSize ; ++i)
    {
        for (const auto &[pos, idx] : v[i])
        {
            output[idx] = a[pos];
        }

        riffle();
    }

    total = 0;
    for (int i = bucketSize + 1 ; i <= n ; ++i)
    {
        for (const auto &[pos, idx] : v[i])
        {
            output[idx] = a[pos];
        }

        riffle();
    }

    assert(total <= bucketSize);
}

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

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

    for (int i = 1 ; i <= q ; ++i)
    {
        int t, idx;
        std::cin >> t >> idx;
        v[std::min(t, (int)sqrt(n))].push_back({idx, i});
    }
}

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

int main()
{
    fastIOI();
    input();
    solve();
    print();

    return 0;
}

Compilation message

Main.cpp: In function 'void riffle()':
Main.cpp:32:40: error: no matching function for call to 'max(llong&, int&)'
   32 |             total = std::max(total, pos);
      |                                        ^
In file included from /usr/include/c++/10/algorithm:61,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
Main.cpp:32:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   32 |             total = std::max(total, pos);
      |                                        ^
In file included from /usr/include/c++/10/algorithm:61,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
Main.cpp:32:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   32 |             total = std::max(total, pos);
      |                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
Main.cpp:32:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   32 |             total = std::max(total, pos);
      |                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
Main.cpp:32:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   32 |             total = std::max(total, pos);
      |                                        ^
Main.cpp:48:40: error: no matching function for call to 'max(llong&, int&)'
   48 |             total = std::max(total, pos);
      |                                        ^
In file included from /usr/include/c++/10/algorithm:61,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
Main.cpp:48:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   48 |             total = std::max(total, pos);
      |                                        ^
In file included from /usr/include/c++/10/algorithm:61,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
Main.cpp:48:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   48 |             total = std::max(total, pos);
      |                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
Main.cpp:48:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   48 |             total = std::max(total, pos);
      |                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
Main.cpp:48:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   48 |             total = std::max(total, pos);
      |                                        ^