Submission #145628

# Submission time Handle Problem Language Result Execution time Memory
145628 2019-08-20T14:14:03 Z dolphingarlic Hacker (BOI15_hac) C++14
Compilation error
0 ms 0 KB
// Basically we want Bytesar to start on the computer with
// the maximum of the minimums of semicircle sums that contain
// that computer, since the operator is able to force him to do that

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000050;

int a[N];
ll sum[N], p[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) cin >> a[i], a[i + n] = a[i];
    for (int i = 1; i <= n * 2; i++) sum[i] = sum[i - 1] + a[i]; // Prefix sums

    int sz = n + 1 >> 1;

    // Sums of semicircles
    for (int i = 1; i <= n; i++) p[i] = sum[i + sz - 1] - sum[i - 1];
    for (int i = n + 1; i <= n * 2; i++) p[i] = p[i - n];

    // Monotonic queue - Easily get min in range
    deque<int> dq;
    for (int i = n - sz + 2; i <= n; i++) {
        while (dq.size() && p[dq.back()] >= p[i]) dq.pop_back();
        dq.push_back(i);
    }

    int ans = 0;

    for (int i = n + 1; i <= 2 * n; i++) {
        while (dq.size() && p[dq.back()] >= p[i]) dq.pop_back();
        dq.push_back(i);
        // Make sure we only consider semicircle sums that contain
        // the current computer i
        while (dq.front() < i - sz + 1) dq.pop_front();
        ans = max(ans, p[dq.front()]);
    }

    cout << ans << '\n';
    return 0;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:23:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int sz = n + 1 >> 1;
              ~~^~~
hac.cpp:44:37: error: no matching function for call to 'max(int&, ll&)'
         ans = max(ans, p[dq.front()]);
                                     ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from hac.cpp:5:
/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:
hac.cpp:44:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
         ans = max(ans, p[dq.front()]);
                                     ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from hac.cpp:5:
/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:
hac.cpp:44:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
         ans = max(ans, p[dq.front()]);
                                     ^
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 hac.cpp:5:
/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:
hac.cpp:44:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
         ans = max(ans, p[dq.front()]);
                                     ^
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 hac.cpp:5:
/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:
hac.cpp:44:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
         ans = max(ans, p[dq.front()]);
                                     ^