QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#543329#7523. Partially Free MealYoralenTL 0ms5844kbC++141.3kb2024-09-01 16:02:302024-09-01 16:02:30

Judging History

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

  • [2024-09-01 16:02:30]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:5844kb
  • [2024-09-01 16:02:30]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define int long long
const int N=200005,inf=1e16,Lim=1e9;
struct node{
	int x,y;
	bool operator <(node A)const{return y<A.y;}
}a[N];
struct Tree{int s,c,ls,rs;}t[N<<6];
int ans[N],n,tot,Rt;
void Add(int &u,int l,int r,int v,int c){
	if(!u)u=++tot;int mid((l+r)>>1);
	t[u].c+=c;t[u].s+=c*v;
	if(l==r)return;
	if(v<=mid)Add(t[u].ls,l,mid,v,c);
	else Add(t[u].rs,mid+1,r,v,c);
}
int Ask(int u,int l,int r,int k){
	int mid((l+r)>>1);if(k==0)return 0;
	if(t[t[u].ls].c>k)return Ask(t[u].ls,l,mid,k);
	else return t[t[u].ls].s+Ask(t[u].rs,mid+1,r,k-t[t[u].ls].c);
}
void Deal(int l,int r,int L,int R){
	if(L>R){return;}
	//printf("%lld %lld\n",L,R);
	int mid((L+R)>>1),res=inf,pos,i;
	for(i=l;i<=r;i++){
		if(i>=mid){
			
			int v=a[i].y+a[i].x+Ask(Rt,1,Lim,mid-1);
		//	printf("%lld %lld\n",i,v);
			if(res>v){res=v,pos=i;}
		}
		Add(Rt,1,Lim,a[i].x,1);
	}
	ans[mid]=res;
	for(i=l;i<=r;i++)Add(Rt,1,Lim,a[i].x,-1);
	Deal(l,pos,L,mid-1);
	for(i=l;i<pos;i++)Add(Rt,1,Lim,a[i].x,1);
	Deal(pos,r,mid+1,R); 
}
signed main(){
	int i;scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld%lld",&a[i].x,&a[i].y);
	sort(a+1,a+1+n);Deal(1,n,1,n);
	for(i=1;i<=n;i++)printf("%lld\n",ans[i]); 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: