QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#267239#4585. Greedy KnapsackNYCU_YamadaCompile Error//C++203.4kb2023-11-27 02:49:152023-11-27 02:49:16

Judging History

你现在查看的是最新测评结果

  • [2023-11-27 02:49:16]
  • 评测
  • [2023-11-27 02:49:15]
  • 提交

answer

#ifndef Yamada
#define Yamada
#include Yamada __FILE__ Yamada

const int B = 35;
const int maxc = 1 << 17;

set<pii> st[B];
int taw[B], tav[B];
int ans[maxc];

void solve() {
    int n, t; cin >> n >> t;
    vector<int> w(n), v(n);
    for (auto &x : w) cin >> x;
    for (auto &x : v) cin >> x;

    int idx = 0;
    for (int i = max(1LL, t - maxc); i <= t; ++i, ++idx) {
        // debug(i);
        int hb = __lg(i);
        st[hb].ee(i, idx);
    }

    for (int i = 0; i < n; ++i) {
        int hb = __lg(w[i]);
        while (SZ(st[hb])) {
            auto it = st[hb].end(); it = prev(it);
            pii cur = *it;
            if (cur.X - taw[hb] < w[i]) break;
            else {
                int nxtw = cur.X - w[i] - taw[hb];
                st[hb].erase(it);
                ans[cur.Y] += v[i] + tav[hb];
                if (nxtw == 0) continue;

                int nxthb = __lg(nxtw);
                st[nxthb].ee(nxtw + taw[nxthb], cur.Y);
                ans[cur.Y] -= tav[nxthb];
            }
        }

        for (int j = hb + 1; j < B; ++j) {
            taw[j] += w[i], tav[j] += v[i];
            while (SZ(st[j])) {
                auto it  = st[j].begin();
                pii cur = *it;
                if (cur.X - taw[j] < (1LL << j)) {
                    int nxtw = cur.X - taw[j];
                    int nxthb = __lg(nxtw);

                    st[j].erase(it);
                    st[nxthb].ee(nxtw + taw[nxthb], cur.Y);
                    ans[cur.Y] += tav[j] - tav[nxthb];
                }
                else break;
            }
        }
    }

    for (int i = 0; i < B; ++i) {
        for (auto it : st[i]) ans[it.Y] += tav[i];
    }
    int tot = 0;
    for (int i = 0; i < idx; ++i) chmax(tot, ans[i]);
    print(tot);
}

signed main() {
    IOS();
    int t = 1; // cin >> t;
    for (int i=1;i<=t;++i) solve();
    return 0;
}

#else

#ifdef local 
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize ("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define double __float80
using pii = pair<int, int>;
template <typename T> using MaxHeap = std::priority_queue<T>;
template <typename T> using MinHeap = std::priority_queue<T, vector<T>, greater<T>>;

#define SZ(a) ((int)(a).size())
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define ee emplace
#define eb emplace_back
#define ef emplace_front
#define pb pop_back
#define pf pop_front
#define X first
#define Y second

#ifdef local
#define IOS() void()
#define debug(...) \
    fprintf(stderr, "\e[1;93m"), \
    fprintf(stderr, "At [%s], line %d: (%s) = ", __FUNCTION__, __LINE__, #__VA_ARGS__), \
    _do(__VA_ARGS__), \
    fprintf(stderr, "\e[0m")
template <typename T> void _do(T &&_t) {cerr << _t << '\n';}
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
#define print(...) \
    fprintf(stderr, "\e[1;96m"), \
    _P(__VA_ARGS__), \
    fprintf(stderr, "\e[0m")
#else
#define IOS() ios_base::sync_with_stdio(0); cin.tie(0)
#define debug(...) void()
#define print(...) _P(__VA_ARGS__)
#define endl '\n'
#endif

template <typename U, typename V> bool chmin(U &u, V v) {return u > v ? u = v, 1 : 0;}
template <typename U, typename V> bool chmax(U &u, V v) {return u < v ? u = v, 1 : 0;}

template <typename T> void _P(T &&_x) {cout << _x << '\n';}
template <typename T, typename ...S> void _P(T &&_x, S &&..._t) {cout << _x << " "; _P(_t...);}

#endif

詳細信息

answer.code: In function ‘void solve()’:
answer.code:19:21: error: no matching function for call to ‘max(long long int, int64_t)’
   19 |     for (int i = max(1LL, t - maxc); i <= t; ++i, ++idx) {
      |                  ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:82,
                 from answer.code:3:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
answer.code:19:21: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int64_t’ {aka ‘long int’})
   19 |     for (int i = max(1LL, t - maxc); i <= t; ++i, ++idx) {
      |                  ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:82,
                 from answer.code:3:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
answer.code:19:21: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int64_t’ {aka ‘long int’})
   19 |     for (int i = max(1LL, t - maxc); i <= t; ++i, ++idx) {
      |                  ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:82,
                 from answer.code:3:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)’
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
answer.code:19:21: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’
   19 |     for (int i = max(1LL, t - maxc); i <= t; ++i, ++idx) {
      |                  ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:82,
                 from answer.code:3:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)’
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
answer.code:19:21: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’
   19 |     for (int i = max(1LL, t - maxc); i <= t; ++i, ++idx) {
      |                  ~~~^~~~~~~~~~~~~~~