제출 #159809

#제출 시각아이디문제언어결과실행 시간메모리
159809DS007Global Warming (CEOI18_glo)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

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

    int n, x;
    cin >> n >> x;

    int t[n];
    for (int i = 0; i < n; i++)
        cin >> t[i];

    int lis1[n + 1];
    fill(lis1, lis1 + n + 1, 2e9);
    lis1[0] = -1;

    int len[n];
    memset(len, 0, sizeof(len));
    int temp = 0;

    for (int i = 0; i < n; i++) {
        auto it = upper_bound(lis1, lis1 + n + 1, t[i]);
        *it = t[i];
        len[i] = max(temp, it - lis1);
        temp = max(temp, len[i]);
    }

    int lis2[n + 1];
    fill(lis2, lis2 + n + 1, -2e9);
    lis2[n] = 2e9;

    int ans = 0;

    for (int i = n - 1; i >= 0; i--) {
        auto it = upper_bound(lis2, lis2 + n + 1, t[i] - x);
        ans = max(ans, len[i] + n - (it - lis2));
        it = upper_bound(lis2, lis2 + n + 1, t[i]);
        lis2[--it - lis2] = t[i];
    }

    cout << ans;
}

컴파일 시 표준 에러 (stderr) 메시지

glo.cpp: In function 'int main()':
glo.cpp:27:37: error: no matching function for call to 'max(int&, long int)'
         len[i] = max(temp, it - lis1);
                                     ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
glo.cpp:27:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long int')
         len[i] = max(temp, it - lis1);
                                     ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
glo.cpp:27:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long int')
         len[i] = max(temp, it - lis1);
                                     ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
glo.cpp:27:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
         len[i] = max(temp, it - lis1);
                                     ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
glo.cpp:27:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
         len[i] = max(temp, it - lis1);
                                     ^
glo.cpp:39:48: error: no matching function for call to 'max(int&, long int)'
         ans = max(ans, len[i] + n - (it - lis2));
                                                ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
glo.cpp:39:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long int')
         ans = max(ans, len[i] + n - (it - lis2));
                                                ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
glo.cpp:39:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long int')
         ans = max(ans, len[i] + n - (it - lis2));
                                                ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
glo.cpp:39:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
         ans = max(ans, len[i] + n - (it - lis2));
                                                ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from glo.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
glo.cpp:39:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
         ans = max(ans, len[i] + n - (it - lis2));
                                                ^