QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#518382#7523. Partially Free MealKLPP#WA 414ms18272kbC++172.7kb2024-08-13 20:01:462024-08-13 20:01:47

Judging History

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

  • [2024-08-13 20:01:47]
  • 评测
  • 测评结果:WA
  • 用时:414ms
  • 内存:18272kb
  • [2024-08-13 20:01:46]
  • 提交

answer

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
typedef long long int lld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)

int n;
vector<pair<lld,lld> >V;
vector<int> per;

ordered_set O;
int ptr;

class FT{
	lld arr[1'000'000];
	int N;
	public:
	void init(){
		N=n;
		rep(i,0,N+1)arr[i]=0;
	}
	void upd(int pos,lld val){
		pos+=1;
		for(;pos<=N;pos+=(pos&(-pos)))arr[pos]+=val;
	}
	lld query(int pos){
		pos++;
		lld ans=0;
		for(;pos>0;pos-=(pos&(-pos))){
			ans+=arr[pos];
		}
		return ans;
	}
};
FT F;

class FT2{
	int arr[1'000'000];
	int N;
	public:
	void init(){
		N=n;
		rep(i,0,N+1)arr[i]=0;
	}
	void upd(int pos,int val){
		pos+=1;
		for(;pos<=N;pos+=(pos&(-pos)))arr[pos]+=val;
	}
	int query(int k){
		//cout<<k<<"\n";
		//rep(i,0,N+1)cout<<arr[i]<<" ";
		//cout<<endl;
		int pot=(1<<30);
		int pos=0;
		int cur=k;
		while(pot>0){
			if(pot+pos<=N){
				int nxt=cur-arr[pot+pos];
				if(nxt>=0){
					cur=nxt;
					pos+=pot;
				}
			}
			pot/=2;
		}
		return pos;
	}
};
FT2 F2;

void adv(){
	ptr++;
	//O.insert(per[ptr]);
	F2.upd(per[ptr],1);
	F.upd(per[ptr],V[ptr].second);
}
void ret(){
	F.upd(per[ptr],-V[ptr].second);
	//O.erase(per[ptr]);
	F2.upd(per[ptr],-1);
	ptr--;
}
lld query(int k){
	//int x=*O.find_by_order(k-1);
	int x=F2.query(k-1);
	return F.query(x);
}
vector<lld> res;
void divideandconquer(int l, int r, int optl,int optr){
	if(l>r){
		while(ptr<optr)adv();
		assert(ptr==optr);
		return;
	}
	//pointer at optl-1
	int mid=(l+r)/2;
	pair<lld,int> ans={1e18,-1};
	for(int pos=optl;pos<=optr;pos++){
		adv();
		if(pos+1>=mid){
			pair<lld,int> can={query(mid)+V[pos].first,mid};
			ans=min(ans,can);
		}
	}
	for(int pos=optl;pos<=optr;pos++){
		ret();
	}
	//cout<<ans.first<<" "<<ans.second<<"\n";
	res[mid]=ans.first;
	int opt=ans.second;
	divideandconquer(l,mid-1,optl,opt);
	ret();
	divideandconquer(mid+1,r,opt,optr);
	assert(ptr==optr);
	
}

void solve(){
	cin>>n;
	F.init();
	F2.init();
	V.resize(n);
	rep(i,0,n){
		cin>>V[i].second>>V[i].first;
	}
	sort(V.begin(),V.end());
	vector<pair<lld,lld>> X(n);
	rep(i,0,n){
		X[i].first=V[i].second;
		X[i].second=i;
	}
	sort(X.begin(),X.end());
	per.resize(n);
	rep(i,0,n){
		per[X[i].second]=i;
	}
	ptr=-1;
	res.resize(n+1);
	divideandconquer(1,n,0,n-1);
	rep(i,1,n+1)cout<<res[i]<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int tt=1;
	//cin>>tt;
	while(tt--){
		solve();
	}
}

詳細信息

Test #1:

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

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 414ms
memory: 18272kb

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:

192284522
465420967
205645515
478779682
828875051
584812649
1321756978
1969208842
1559060466
2121195265
2768647129
2137300252
3340465826
3987917690
4327066230
4974518094
5793273016
5305948960
6969858475
7911863623
7129983474
7948738396
8890743544
4170096709
9491859694
10433864842
9015567317
99562244...

result:

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