QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#537592#7523. Partially Free MealNew_Folder#TL 0ms3484kbC++141.8kb2024-08-30 16:22:122024-08-30 16:22:12

Judging History

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

  • [2024-08-30 16:22:12]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3484kb
  • [2024-08-30 16:22:12]
  • 提交

answer

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
//#define pi 3.1415926
typedef long long ll;
using namespace std;
int mod=998244353;

int fp(int a,int b){
	int ans=1;
	while(b){
		if(b&1) ans*=a,ans%=mod;
		a*=a,a%=mod;
		b>>=1;
	}
	return ans;
}

vector<pair<int,int>> vec;

bool ccmp(pair<int,int> p1,pair<int,int> p2){
	return p1.second<p2.second;
}

struct cmp{
    bool operator()(int p1,int p2){
        if(vec[p1].first+vec[p1].second<vec[p2].first+vec[p2].second) return 0;
		else if(vec[p1].first+vec[p1].second>vec[p2].first+vec[p2].second) return 1;
		else{
			if(vec[p1].second<vec[p2].second) return 1;
			else return 0;
		}
    }
};

void solve(){
	int n;cin>>n;
	int in1,in2;int ptr=0;
	vec.resize(n);
	unordered_set<int> vis;
	priority_queue<int,vector<int>,greater<int>> q1;
	priority_queue<int,vector<int>,cmp> q2;
	for(int i=0;i<=n-1;i++) cin>>in1>>in2,vec[i]=make_pair(in1,in2);
	sort(vec.begin(),vec.end(),ccmp);
	for(int i=0;i<=n-1;i++) q2.push(i);
	vector<int> ans(n+1);int tmp=0;
	for(int z=1;z<=n;z++){
		bool flag=0;
		while(vis.count(q2.top())) q2.pop();
		if(q2.empty()) ans[z]=q1.top(),q1.pop();
		else if(q1.empty()) ans[z]=vec[q2.top()].first+vec[q2.top()].second-tmp+ans[z-1],flag=1;
		else{
			if(vec[q2.top()].first+vec[q2.top()].second-tmp<=q1.top()) ans[z]=vec[q2.top()].first+vec[q2.top()].second-tmp+ans[z-1],flag=1;
			else ans[z]=ans[z-1]+q1.top(),q1.pop();
		}
		if(flag){
			tmp=vec[q2.top()].second;
			vis.insert(q2.top());q2.pop();
			while(ptr<=n-1&&vec[ptr].second<=tmp){
				if(vis.count(ptr)) ptr++;
				else vis.insert(ptr),q1.push(vec[ptr].first),ptr++;
			} 
		}
	}
	for(int i=1;i<=n;i++) cout<<ans[i]<<"\n";
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//int t;cin>>t;while(t--) 
	solve();
	return 0;
}	

详细

Test #1:

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

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: