QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#234697#7523. Partially Free Meal1677118046WA 168ms109556kbC++142.4kb2023-11-01 20:57:442023-11-01 20:57:45

Judging History

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

  • [2023-11-01 20:57:45]
  • 评测
  • 测评结果:WA
  • 用时:168ms
  • 内存:109556kb
  • [2023-11-01 20:57:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nn=2e5+10;
ll id=0;
int sz;
ll root[nn];
vector<ll>an;
struct node2{
	ll a,b;
}C[nn];
struct node{
	int lson,rson;
	ll sum;//因为求的是前k小的和故要用前缀和来维护。
	ll num; 
}tree[40*nn];
int getid(int x){
	return lower_bound(an.begin(),an.end(),x)-an.begin()+1;
}
int build(int l,int r){//先建立初始的树 
	int now=++id;
	tree[now].sum=0;
	tree[now].num=0;
	
	if(l==r)return now;
	int mid=(l+r)/2;
	tree[now].lson=build(l,mid);
	tree[now].rson=build(mid+1,r);
	return now;
}
int update(int l,int r,int pos,int pre)//建立新版本的节点 
{
	id++;
	tree[id]=tree[pre];
	tree[id].num++;
	tree[id].sum+=an[pos-1];
	int now=id;
	if(l==r&&l==pos){
		return now;
	}
	int mid=(l+r)/2;
	if(mid>=pos){
		tree[now].lson=update(l,mid,pos,tree[pre].lson);
	}else{
		tree[now].rson=update(mid+1,r,pos,tree[pre].rson);
	}
	return now;
}
ll query(int l,int r,int k,int now,int pre){//前k小的值 
	if(l==r){
		if(tree[now].num-tree[pre].num==0)return 0;
		return (tree[now].sum-tree[pre].sum)/(tree[now].num-tree[pre].num)*k;
	}
	ll mid=(l+r)/2;
	int id1=tree[now].lson;
	int id2=tree[pre].lson;
	if(tree[id1].num-tree[id2].num>=k){
		return query(l,mid,k,id1,id2);
	}else{
		return (tree[id1].sum-tree[id2].sum)+query(mid+1,r,k-(tree[id1].num-tree[id2].num),tree[now].rson,tree[pre].rson);
	}
}
ll ans[nn];
void get(int l,int r,int posl,int posr){//得到有效区间的最值 
	ll mid=(l+r)/2;
	if(l>r)return;
	ll a0=1e9+10;
	ll pos=0;
	for(int i=max(mid,1ll*posl);i<=posr;i++){
		ll a1=query(1,sz,mid-1,root[i-1],root[0]);
		if(a1+C[i].b+C[i].a<a0){
			a0=a1+C[i].b+C[i].a;
			pos=i;
		}
	}
	ans[mid]=a0;
	if(l==r)return;
	get(l,mid-1,posl,pos);
	get(mid+1,r,pos,posr);
}

bool cmp1(node2 a,node2 b){
	if(a.b==b.b)return a.a<b.a;
	return a.b<b.b;
}
void solve(){
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>C[i].a>>C[i].b;
		an.push_back(C[i].a);
	}
	sort(C+1,C+n+1,cmp1);
	sort(an.begin(),an.end());
	an.erase(unique(an.begin(),an.end()),an.end());
	sz=an.size();
	root[0]=build(1,sz);
	for(int i=1;i<=n;i++){
		int pos=getid(C[i].a);
		root[i]=update(1,sz,pos,root[i-1]);
	}
	get(1,n,1,n);
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<"\n";
	}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 168ms
memory: 109556kb

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:

1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
1000000010
100...

result:

wrong answer 1st lines differ - expected: '1318594', found: '1000000010'