75pts RE 5个点求调
查看原帖
75pts RE 5个点求调
303105
haiming楼主2024/11/28 19:12

rt

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,i,j,x,p1,q1,t;
void read(int &x){
	x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while('0'<=ch&&ch<='9')x=x*10+ch-48,ch=getchar();
}
struct node{int x,y,z;}a[300000];
bool cmp(node x,node y){return x.y<y.y;}
struct note{int x,y;};
bool operator <(const note &aa,const note &bb){return aa.x>bb.x||(aa.x==bb.x&&aa.y>bb.y);}
priority_queue<note>q;
priority_queue<int,vector<int>,greater<int> >p;
vector<int>b[300000];
signed main(){
//	freopen("pa.in","r",stdin);
//	freopen("pa.out","w",stdout);
	read(n);read(m);
	for(i=1;i<=n;i++)
		read(a[i].x),read(a[i].y),a[i].z=i;
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=m;i++)p.push(i),p1++;
	for(i=1;i<=n;i++)b[i].push_back(0);
	for(i=1;i<=n;i++){
		while(q1&&q.top().x<=a[i].y){
			p.push(q.top().y);
			q.pop();
			p1++;q1--;
		}
		if(!p1){
			p.push(q.top().y);
			x=q.top().x;
			q.pop();p1++;q1--;
		}
		t=p.top();p.pop();p1--;
		x=max(x,a[i].y);
		b[t].push_back(a[i].z);b[t][0]++;
		q.push({x+a[i].x,t});q1++;
	}
	for(i=1;i<=n;i++)
		if(b[i][0])sort(b[i].begin()+1,b[i].end());
	for(i=1;i<=m;i++){
		printf("%lld ",b[i][0]);
		for(j=1;j<=b[i][0];j++)
			printf("%lld ",b[i][j]);
		putchar(10);
	}
	return 0;
}
2024/11/28 19:12
加载中...