QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796156#9520. Concave HullXiaoretaWRE 0ms0kbC++201.7kb2024-12-01 13:28:132024-12-01 13:28:13

Judging History

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

  • [2024-12-01 13:28:13]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-12-01 13:28:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

struct node{
	int pos,id;
}b[100010];
int a[100010],now[100010];
int n,m;

bool cmp(node x,node y){
	return x.pos<y.pos;
}

void solve(){
	cin>>n>>m;
	set<pair<int,int>> q;
	set<int> p[n+10];
	vector<int> cnt(n+10,0);
	for(int i=1;i<=n;i++){
		cin>>a[i];
		now[i]=a[i];
	}
	for(int i=1;i<=m;i++){
		cin>>b[i].pos>>b[i].id;
		p[b[i].id].insert(b[i].pos);
	}
	sort(b+1,b+1+m,cmp);
	for(int i=1;i<=m;i++){
		if(!cnt[b[i].id]) {
			q.insert({b[i].pos,b[i].id});
		}
		cnt[b[i].id]++;
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		if(cnt[i]==0){
			sum+=a[i];
		}
	}
	int ans=0;
	for(int i=1;i<=m;i++){
		if(!q.size()){
			int cha=b[i].pos-ans;
			ans+=min(sum,cha);
			sum=max(0ll,sum-cha);
		}
		vector<pair<int,int>> del;
		for(auto [x,y]:q){
			int cha=b[i].pos-ans;
			ans+=min(now[y],cha);
			now[y]=max(0ll,now[y]-cha);
			if(now[y]==0ll){
				del.push_back({x,y});
			}
			if(ans>=b[i].pos){
				break;
			}
		}
		for(auto [x,y]:del){
			q.erase({x,y});
		}
		if(ans<b[i].pos){
			int cha=b[i].pos-ans;
			ans+=min(sum,cha);
			sum=max(0ll,sum-cha);
		}
		if(ans>=b[i].pos){
			now[b[i].id]=a[b[i].id];
			cnt[b[i].id]--;
			if(cnt[b[i].id]==0ll) {
				sum+=now[b[i].id];
			}
			else{
				auto it=p[b[i].id].upper_bound(ans);
				if(it==p[b[i].id].end()){
					continue;
				}else{
					int index=*it;
					q.insert({index,b[i].id});					
				}
			}
		}
		else{
			break;
		}
	}
	cout<<ans+sum<<'\n';
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T=1;
	cin>>T; 
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2
6
-2 0
1 -2
5 2
0 4
1 2
3 1
4
0 0
1 0
0 1
1 1

output:


result: