QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#500818#6416. Classical Scheduling Problemucup-team2307#WA 56ms3720kbC++203.4kb2024-08-01 21:08:102024-08-01 21:08:11

Judging History

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

  • [2024-08-01 21:08:11]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:3720kb
  • [2024-08-01 21:08:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back

struct FT {
    vector<ll> s;
    FT(int n) : s(n) {}
    void update(int pos, ll dif) { // a[pos] += dif
        for (; pos < sz(s); pos |= pos + 1) s[pos] += dif;
    }
    ll query(int pos) { // sum of values in [0, pos)
        ll res = 0;
        for (; pos > 0; pos &= pos - 1) res += s[pos-1];
        return res;
    }
    int lower_bound(ll sum) {// min pos st sum of [0, pos] >= sum
        // Returns n if no sum is >= sum, or -1 if empty sum is.
        if (sum <= 0) return -1;
        int pos = 0;
        for (int pw = 1 << 25; pw; pw >>= 1) {
            if (pos + pw <= sz(s) && s[pos + pw-1] < sum)
                pos += pw, sum -= s[pos-1];
        }
        return pos;
    }
};

struct Topic
{
    int a,b,ind;
    auto operator<=>(const Topic&)const =default;
};

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

    int q;
    cin>>q;
    while(q--)
    {
        int n,t;
        cin>>n>>t;
        vector<Topic> topics(n);
        for(int i=0;i<n;i++)
            cin>>topics[i].a>>topics[i].b,
            topics[i].ind=i+1;
        sort(all(topics));
        vi pref_a(n+1);
        for(int i=0;i<n;i++)
            pref_a[i+1]=pref_a[i]+topics[i].a;
        vector<vi> b_to_i(n+1);
        for(int i=0;i<n;i++)
            b_to_i[topics[i].b].pb(i);
        FT good_sum(n),good_cnt(n),bad_sum(n),bad_cnt(n);
        for(int i=0;i<n;i++)
            bad_sum.update(i,topics[i].a),
            bad_cnt.update(i,1);
        pii ans={0,0};
        for(int k=1;k<=n;k++)
        {
            if(pref_a[k]>t)
                break;
            for(int i:b_to_i[k])
                good_sum.update(i,topics[i].a),
                good_cnt.update(i,1),
                bad_sum.update(i,-topics[i].a),
                bad_cnt.update(i,-1);
            int lo=k,hi=n;
            while(lo<hi)
            {
                int mi=(lo+hi+1)/2;
                int my_good_cnt=good_cnt.query(mi);
                if(my_good_cnt>k)
                {
                    hi=mi-1;
                    continue;
                }
                int my_bad_cnt=k-my_good_cnt;
                int bad_pos=bad_cnt.lower_bound(my_bad_cnt)+1;
                int sum=good_sum.query(mi)+bad_sum.query(bad_pos);
                if(sum<=t)
                    lo=mi;
                else
                    hi=mi-1;
            }
            {
                int mi=(lo+hi+1)/2;
                int my_good_cnt=good_cnt.query(mi);
                int my_bad_cnt=k-my_good_cnt;
                ans=max(ans,pii(my_good_cnt,my_bad_cnt));
            }
        }
        auto[my_good_cnt,my_bad_cnt]=ans;
        int k=my_good_cnt+my_bad_cnt;
        cout<<my_good_cnt<<"\n";
        cout<<k<<"\n";
        for(auto[a,b,ind]:topics)
        {
            if(b>=k)
            {
                if(my_good_cnt)
                    cout<<ind<<" ",my_good_cnt--;
            }
            else
            {
                if(my_bad_cnt)
                    cout<<ind<<" ",my_bad_cnt--;
            }
        }
        cout<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3536kb

input:

2
4 100
20 1
40 4
60 3
30 3
1 5
10 1

output:

2
3
1 4 2 
0
0


result:

ok ok, 2 test cases (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 56ms
memory: 3720kb

input:

10000
21 1892
174 13
604 15
170 2
413 11
899 2
531 12
651 17
553 9
429 8
837 14
937 12
577 7
532 11
19 2
173 10
165 6
762 15
221 6
945 13
302 19
7 3
54 26066
812 31
432 24
240 37
171 39
204 47
174 30
569 1
467 5
624 42
734 35
907 3
568 23
802 40
991 32
119 13
187 27
739 42
891 14
550 44
374 16
483 1...

output:

7
8
21 15 1 20 4 9 6 13 
53
53
28 
12
13
5 3 11 10 
7
15
38 40 21 37 8 24 28 11 43 33 41 14 13 1 15 
10
14
27 16 7 8 12 15 9 18 14 20 4 2 17 24 
0
0

10
11
5 13 8 1 
0
1

0
3

2
5
6 12 3 1 10 
15
15
11 
9
10
11 9 1 
9
9
1 15 8 
47
51
43 2 48 25 35 52 19 33 9 56 26 
18
23
27 28 29 4 7 21 18 19 26 9 1...

result:

wrong answer too much time taken to learn the topics: 2561 > 1892 (test case 1)