提交时间:2023-12-22 14:00:02

运行 ID: 117189

#include<bits/stdc++.h> using namespace std; inline int read(){ int x=0,f=1;char ch=getchar(); for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch^48); return f*x; } int n,x,y,a[200005],b[200005],num[200005]; int main(){ n=read(); for(int i=1;i<=n;i++) x=read(),y=read(),a[i]=x,b[i]=x+y; sort(a+1,a+n+1); sort(b+1,b+n+1); for(int i=1,j=1,now=0,lst=0;i<=n||j<=n;){ while(i<=n&&j<=n&&a[i]==b[j]) i++,j++; if(i>n||a[i]>b[j])num[now]+=b[j]-lst,now--,lst=b[j],j++; else num[now]+=a[i]-lst,now++,lst=a[i],i++; } for(int i=1;i<=n;i++) printf("%d ",num[i]); putchar(10); return 0; }