QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#314557#7750. Revenge on My Bossarnold518WA 0ms4080kbC++172.4kb2024-01-25 20:27:512024-01-25 20:27:52

Judging History

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

  • [2024-01-25 20:27:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4080kb
  • [2024-01-25 20:27:51]
  • 提交

answer

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

struct Data
{
    ll a, b, c;
    int p;
};

struct Frac
{
    ll u, d;
    Frac(ll u, ll d) : u(u), d(d) {}
    bool operator < (const Frac &ot) const { return (__int128)u*ot.d < (__int128)ot.u*d; }
};

int TC, N;
Data A[MAXN+10];

int main()
{
    scanf("%d", &TC);
    while(TC--)
    {
        scanf("%d", &N);
        for(int i=1; i<=N; i++) scanf("%lld%lld%lld", &A[i].a, &A[i].b, &A[i].c), A[i].p=i;

        vector<int> ans;
        vector<int> V1, V2;
        for(int i=1; i<=N; i++)
        {
            if(A[i].a<=A[i].b) V1.push_back(i);
            else V2.push_back(i);
        }

        ll SA=0, SB=0;
        for(int i=1; i<=N; i++) SA+=A[i].a, SB+=A[i].b;

        ll lo=0, hi=1e18;
        while(lo+1<hi)
        {
            ll mid=lo+hi>>1;

            vector<pair<Frac, int>> V;
            for(auto i : V1) V.push_back({{mid-A[i].a*A[i].c, A[i].c}, i});
            sort(V.begin(), V.end());

            ll t=SB;
            bool flag=true;
            for(auto [v, p] : V)
            {
                t+=A[p].b-A[p].a;
                if(v<Frac(t, 1)) flag=false;
            }
            if(flag) hi=mid;
            else lo=mid;
        }
        {
            vector<pair<Frac, int>> V;
            for(auto i : V1) V.push_back({{hi-A[i].b*A[i].c, A[i].c}, i});
            sort(V.begin(), V.end());
            for(auto it : V) ans.push_back(it.second);
        }

        lo=0, hi=1e18;
        while(lo+1<hi)
        {
            ll mid=lo+hi>>1;

            vector<pair<Frac, int>> V;
            for(auto i : V2) V.push_back({{mid-A[i].b*A[i].c, A[i].c}, i});
            sort(V.begin(), V.end());

            ll t=SB;
            bool flag=true;
            for(auto [v, p] : V)
            {
                t+=A[p].a-A[p].b;
                if(v<Frac(t, 1)) flag=false;
            }
            if(flag) hi=mid;
            else lo=mid;
        }
        {
            vector<pair<Frac, int>> V;
            for(auto i : V2) V.push_back({{hi-A[i].b*A[i].c, A[i].c}, i});
            sort(V.begin(), V.end());
            for(auto it : V) ans.push_back(it.second);
        }
        
        for(auto it : ans) printf("%d ", it); printf("\n");
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4080kb

input:

2
4
1 1 4
5 1 5
1 9 1
9 8 1
9
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9
3 2 3
8 4 6
2 6 8
3 2 7

output:

1 3 2 4 
2 8 4 3 5 9 7 1 6 

result:

wrong answer Wrong Answer on Case#2