Submission #940181

# Submission time Handle Problem Language Result Execution time Memory
940181 2024-03-07T06:28:09 Z haxorman Financial Report (JOI21_financial) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mxN = 3e5 + 7;
const int SZ = exp2(ceil(log2(mxN)));
const int INF = 1e9 + 7;

int n, d, arr[mxN], seg[4*mxN], nex[mxN], dp[mxN];

void update(int ind, int val) {
    seg[ind+=SZ] = val;
    while (ind /= 2) {
        seg[ind] = max(seg[2*ind], seg[2*ind+1]);
    }
}

int query(int lo, int hi, int ind = 1, int l = 0, int r = SZ - 1) {
    if (lo > r || l > hi) {
        return -INF;
    }

    if (lo <= l && r <= hi) {
        return seg[ind];
    }

    int mid = (l+r)/2;
    return max(query(lo,hi,2*ind,l,mid), query(lo,hi,2*ind+1,mid+1,r));
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> d;
    
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    arr[n] = INT_MAX;
    
    vector<int> st = {n};
    for (int i = n-1; i >= 0; --i) {
        while (st.size() && arr[st.back()] <= arr[i]) {
            st.pop_back();
        }
        nex[i] = st.back();
        st.push_back(i);

        if (i < n-1) {
            update(i, -INF);
        }
    }
    update(n-1, 1);
    update(n, -INF);

    for (int i = n-2; i >= 0; --i) {
        dp[i] = max(query(nex[i], min(n, nex[i]+d-1)) + 1,
                   (query(i, i+d) ? 1 : -1));

        update(i, (dp[i] < 0 ? -INF : dp[i]));
    }

    cout << query(0, n-1) << "\n";
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:59:44: error: no matching function for call to 'max(long long int, int)'
   59 |                    (query(i, i+d) ? 1 : -1));
      |                                            ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 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:59:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   59 |                    (query(i, i+d) ? 1 : -1));
      |                                            ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 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:59:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   59 |                    (query(i, i+d) ? 1 : -1));
      |                                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 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:59:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   59 |                    (query(i, i+d) ? 1 : -1));
      |                                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 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:59:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   59 |                    (query(i, i+d) ? 1 : -1));
      |                                            ^