QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#236593#7523. Partially Free MealCryingRE 1ms5624kbC++141.9kb2023-11-04 08:42:542023-11-04 08:42:55

Judging History

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

  • [2023-11-04 08:42:55]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5624kb
  • [2023-11-04 08:42:54]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const ll MAXN = 2e5+10,MAXM = 6e6+10,INF = 1e18,M = 1e9;

void tomin(ll& x,ll y){x = min(x,y);}
void tomax(ll& x,ll y){x = max(x,y);}

int n,rt[MAXN];
typedef array<int,2> pr;
pr a[MAXN];

#define lc(x) (t[x].lc)
#define rc(x) (t[x].rc)
#define mid ((l+r)>>1)
struct Seg{
	int lc,rc,cnt;
	ll sum;
}t[MAXM];
int tot;

void pu(int x){
	t[x].cnt = t[lc(x)].cnt + t[rc(x)].cnt;
	t[x].sum = t[lc(x)].sum + t[rc(x)].sum;
}
int mdf(int p,int l,int r,int pos){
	int x = ++tot;t[x] = t[p];
	if(l==r){
		t[x].cnt++;
		t[x].sum+=l;
		return x;
	}
	(pos<=mid)?(lc(x)=mdf(lc(x),l,mid,pos)):(rc(x)=mdf(rc(x),mid+1,r,pos));
	pu(x); return x;
}
ll qry(int x,int l,int r,int k){
	if(t[x].cnt < k)return INF;
	if(t[x].cnt == k)return t[x].sum;

	assert(l<r);

	if(t[lc(x)].cnt >= k)return qry(lc(x),l,mid,k);
	else return t[lc(x)].sum + qry(rc(x),mid+1,r,k-t[lc(x)].cnt);
}

#undef lc
#undef rc
#undef mid

ll ans[MAXN];

void calc(int x,int y,int l,int r){
	if(x>y || l>r)return;
	int mid = (x+y)>>1; //求mid的最优解
	ll val = INF,pos = -1;
	rep(i,l,r){
		ll cost = a[i][0] + qry(rt[i],1,M,mid);
		if(val > cost){
			val = cost;
			pos = i;
		}
	}
	assert(pos != -1);
	tomin(ans[mid],val);
	calc(x,mid-1,l,pos);
	calc(mid+1,y,pos,r);
}

int main(){
	ios::sync_with_stdio(false);

	cin>>n;
	rep(i,1,n)cin>>a[i][1]>>a[i][0];
	sort(a+1,a+1+n);

	rep(i,1,n){
		rt[i] = mdf(rt[i-1],1,M,a[i][1]);
	}

	rep(i,1,n)ans[i] = INF;

	calc(1,n,1,n);

	rep(i,1,n)cout<<ans[i]<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5624kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Runtime Error

input:

200000
466436993 804989151
660995237 756645598
432103296 703610564
6889895 53276988
873617076 822481192
532911431 126844295
623111499 456772252
937464699 762157133
708503076 786039753
78556972 5436013
582960979 398984169
786333369 325119902
930705057 615928139
924915828 506145001
164984329 208212435...

output:


result: