QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#208813#6416. Classical Scheduling ProblemConfucianDonutCompile Error//C++143.5kb2023-10-09 21:05:292023-10-09 21:05:29

Judging History

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

  • [2023-10-09 21:05:29]
  • 评测
  • [2023-10-09 21:05:29]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int n,t;

struct item {
    long long second;
    long long first;
    int id;
};

bool operator<(item a, item b) {
    return (a.first<b.first);
}

bool comp(item a, item b) {
    return (a.second<b.second);
}

item a[300000];

long long idx;

bool test(int x) {
    if (x-1>n-1) {
        return false;
    }
    priority_queue <long long> pq;
    long long sum = 0;
    for (int i=0; i<x-1; i++) {
        pq.push(a[i].second);
        sum+=a[i].second;
    }
    long long pre[n];
    for (int i=x-1; i<n; i++) {
        //cout << "hello" << endl;
        pre[i] = sum;
        if (x==1) {
            continue;
        }
        sum+=a[i].second;
        pq.push(a[i].second);
        //cout << "REM:" << pq.top() << " " << sum << endl;
        sum-=pq.top();
        pq.pop();
    }
    priority_queue <long long> pt;
    sum = 0;
    long long suf[n];
    for (int i=n-1; i>=x-1; i--) {
        if (a[i].first-x>n-1-i) {
            //cout << "REM:" << i << endl;
            suf[i] = -1;
            pt.push(a[i].second);
            //cout << "ADD:" << a[i].second << " " << pt.size() << endl;
            sum+=a[i].second;
            continue;
        }
        //cout << "REQ:" << i << " " << a[i].first-x << " " << x << endl;
        //cout << "CHECK:" << pt.size() << " " << a[i].second << " " << a[i].first-x << " " << (pt.size()>0) << " " << (pt.size()>(a[i].first-x)) << endl;
        while (pt.size()>0&&pt.size()>max(0,a[i].first-x)) {
            sum-=pt.top();
            //cout << "REM:" << pt.top() << endl;
            pt.pop();
        }
        //cout << "SUM " << sum << endl;
        suf[i] = sum;
        sum+=a[i].second;
        pt.push(a[i].second);
    }
    long long minans = 1e9;
    long long minidx = 0;
    for (int i=x-1; i<n; i++) {
        if (suf[i]==-1) {
            //cout << "bruh" << endl;
            break;
        }
        //cout << pre[i] << " " << suf[i] << " " << a[i].second << endl;
        if (pre[i]+suf[i]+a[i].second<minans) {
            minans = pre[i]+suf[i]+a[i].second;
            minidx = i;
        }
    }
    //cout << "MIN:" << minans << " " << t << endl;
    if (minans<=t) {
        idx =  minidx;
        return true;
    }else{
        return false;
    }
}

int main() {
    int q;
    cin >> q;
    for (int asdf=0; asdf<q; asdf++) {
        cin >> n >> t;
        for (int i=0; i<n; i++) {
            cin >> a[i].second >> a[i].first;
            a[i].id = i;
        }
        sort(a,a+n);
        long long step = 1<<(31-__builtin_clz(n)+1);
        long long p = 0;
        while (step>0) {
            //cout << asdf <<":" << step << " " << p << endl;
            if (test(p+step)) {
                p+=step;
            }
            //cout << "END" << endl;
            step=step>>1;
        }
        cout << p << endl;
        if (p==0) {
            cout << 0 << endl;
            continue;
        }
        //cout << "ANS:" << idx << endl;
        cout << max(p,a[idx].first) << " ";
        //cout << "IDX:" << idx << endl;
        if (idx>0) {
            sort(a,a+idx,comp);
        }
        sort(a+idx+1,a+n,comp);
        for (int i=0; i<p-1; i++) {
            cout << a[i].id+1 << " ";
        }
        cout << a[idx].id+1 << " ";
        for (int i=idx+1; i<idx+a[idx].first-p+1; i++) {
            cout << a[i].id+1 << " ";
        }cout << endl;
        //cout << "TC OVER" << endl;
    }
}

详细

answer.code: In function ‘bool test(int)’:
answer.code:64:42: error: no matching function for call to ‘max(int, long long int)’
   64 |         while (pt.size()>0&&pt.size()>max(0,a[i].first-x)) {
      |                                       ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from answer.code:1:
/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:64:42: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long long int’)
   64 |         while (pt.size()>0&&pt.size()>max(0,a[i].first-x)) {
      |                                       ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from answer.code:1:
/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:64:42: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long long int’)
   64 |         while (pt.size()>0&&pt.size()>max(0,a[i].first-x)) {
      |                                       ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from answer.code:2:
/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:64:42: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘int’
   64 |         while (pt.size()>0&&pt.size()>max(0,a[i].first-x)) {
      |                                       ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from answer.code:2:
/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:64:42: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘int’
   64 |         while (pt.size()>0&&pt.size()>max(0,a[i].first-x)) {
      |                                       ~~~^~~~~~~~~~~~~~~~