QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#649747#7750. Revenge on My BossLavender_FieldWA 1ms3864kbC++202.8kb2024-10-18 09:42:502024-10-18 09:42:52

Judging History

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

  • [2024-10-18 09:42:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3864kb
  • [2024-10-18 09:42:50]
  • 提交

answer

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define ROF(i,a,b) for(int i = a; i >= b; --i)
typedef long long ll;
using namespace std;

inline int rd() {
	int r = 0; bool w = false; char ch = getchar();
	while( ch < '0' || ch > '9' ) w = !(ch^45), ch = getchar();
	while( ch >= '0' && ch <= '9' ) r = (r<<1) + (r<<3) + (ch^48), ch = getchar();
	return w ? -r : r;
}

#define MAXN 100
const ll INF = 1e18;
int n;
int a[MAXN+5], b[MAXN+5], c[MAXN+5];
int otp[MAXN+5], out[MAXN+5];
ll B, sum;

struct node {
    double e;
    int d, id;
}arr[MAXN+5];
bool cmp(const node &a , const node &b) {
    return a.e < b.e;
}

int ag[MAXN+5];
#define lson (p<<1)
#define rson ((p<<1)+1)
void pushup( int p ) {
    if( arr[ag[lson]].d > arr[ag[rson]].d ) ag[p] = ag[lson];
    else ag[p] = ag[rson];
}
void build( int p = 1 , int l = 1 , int r = n ) {
    if( l == r ) {
        ag[p] = l;
        return;
    }
    int mid = (l + r) >> 1;
    build(lson, l, mid);
    build(rson, mid+1, r);
    pushup(p);
}
int query( int l , int r , int p = 1 , int L = 1 ,  int R = n ) {
    if( l == L && r == R ) {
        return ag[p];
    }
    int mid = (L + R) >> 1;
    if( r <= mid ) return query(l, r, lson, L, mid);
    if( l > mid ) return query(l, r, rson, mid+1, R);
    int lag = query(l, mid, lson, L, mid);
    int rag = query(mid+1, r, rson, mid+1, R);
    if( arr[lag].d > arr[rag].d ) return lag;
    else return rag;
}
void update( int x , int p = 1 , int L = 1 , int R = n ) {
    if( L == R ) {
        arr[x].d = -1e9;
        return;
    }
    int mid = (L + R) >> 1;
    if( x <= mid ) update(x, lson, L, mid);
    else update(x, rson, mid+1, R);
    pushup(p);
}

bool chk( ll x ) {
    ll now = sum;
    FOR(i,1,n) arr[i].e = (double)x / c[i] - b[i] - B, arr[i].d = a[i] - b[i], arr[i].id = i;
    sort(arr+1, arr+1+n, cmp);
    build();
    int p = n+1;
    ROF(i, n, 1) {
        ROF(j, 18, 0) if( p - (1<<j) >= 1 && arr[p-(1<<j)].e >= now ) p -= 1<<j;
        ROF(j, 18, 0) if( p + (1<<j) <= n+1 && arr[p+(1<<j)-1].e < now ) p += 1<<j;
        if( p == n+1 ) return 0;
        int s = query(p, n);
        if( arr[s].d == -1e9 ) return 0;
        now -= arr[s].d;
        otp[i] = arr[s].id;
        update(s);
    }
    return 1;
}
void solve() {
    B = 0, sum = 0;
    n = rd();
    FOR(i,1,n) a[i] = rd(), b[i] = rd(), c[i] = rd(), B += b[i], sum += a[i] - b[i];
    ll l = 0, r = INF, ans = 0;
    while( l <= r ) {
        ll mid = (l + r) >> 1;
        if( chk(mid) ) {
            r = mid - 1;
            ans = mid;
            FOR(i, 1, n) out[i] = otp[i];
        } else l = mid + 1;
    }
    // printf("%lld\n", ans);
    FOR(i,1,n) printf("%d ",out[i]);
    putchar('\n');
}

int main() {
    int T = rd(); while( T-- ) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3864kb

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:

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

result:

wrong answer Wrong Answer on Case#2