QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#468410#7523. Partially Free Mealliuzhenhao09TL 1ms5952kbC++201.6kb2024-07-08 20:39:122024-07-08 20:39:12

Judging History

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

  • [2024-07-08 20:39:12]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5952kb
  • [2024-07-08 20:39:12]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int SZ = 1e9;
const int INF = 1e16 + 7;
struct node{
	int a,b;
	bool operator <(const node& kkk)const{
		return b < kkk.b;
	}
}x[200010];
int n,tot = 0;
int rt[200010],sz[10000010],val[10000010],ls[10000010],rs[10000010],ans[200010];
void pushup(int i){
	sz[i] = sz[ls[i]] + sz[rs[i]];
	val[i] = val[ls[i]] + val[rs[i]];
}
int New(int i){
	tot++;
	sz[tot] = sz[i],val[tot] = val[i],ls[tot] = ls[i],rs[tot] = rs[i];
	return tot;
}
void upd(int& i,int l,int r,int pos,int v1,int v2){
	i = New(i);
	sz[i] += v1;
	val[i] += v2;
	if(l == r) return;
	int mid = (l + r) >> 1;
	if(pos <= mid) upd(ls[i],l,mid,pos,v1,v2);
	else upd(rs[i],mid + 1,r,pos,v1,v2);
	pushup(i);
}
int query(int i,int l,int r,int rk){
	if(!i || !rk) return 0;
	if(l == r) return l;
	int mid = (l + r) >> 1;
	if(rk <= sz[ls[i]]) return query(ls[i],l,mid,rk);
	else return val[ls[i]] + query(rs[i],mid + 1,r,rk - sz[ls[i]]);
}
void solve(int l,int r,int ql,int qr){
	int mid = (l + r) >> 1;
	int tl = max(ql,mid),tr = qr;
	int mn = INF,id = -1;
	for(int i = tl; i <= tr; i++){
		int tmp = x[i].b + x[i].a + query(rt[i - 1],1,SZ,mid - 1);
		if(mn > tmp) mn = tmp,id = i;
	}
	ans[mid] = mn;
	if(l == r) return;
	solve(l,mid - 1,ql,id);
	solve(mid + 1,r,id,qr); 
}
signed main(){
	scanf("%lld",&n);
	for(int i = 1; i <= n; i++) scanf("%lld %lld",&x[i].a,&x[i].b);
	sort(x + 1,x + n + 1);
	for(int i = 1; i <= n; i++) rt[i] = rt[i - 1],upd(rt[i],1,SZ,x[i].a,1,x[i].a);
	solve(1,n,1,n);	
	for(int i = 1; i <= n; i++) printf("%lld\n",ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Time Limit Exceeded

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: