Description
给你N个区间,分别记为[li,ri],li为左端点,ri为区间长度
现在问你:
有多少个点正好被1个不同区间覆盖
有多少个点正好被2个不同区间覆盖
......
有多少个点正好被n个不同区间覆盖
Format
Input
一行给出数字N
接下来N行,给出[li,ri]
N<=2e5
li,ri<=1e9
Output
输出1行,N个数字
Samples
输入数据 1
3
1 2
2 3
3 1
Copy
输出数据 1
2 2 0
#include<bits/stdc++.h>
using namespace std;
int n,o[1001210],w=0,x,y,z;
struct qq{
int a,b;
}p[1000091];
bool cmp(qq a,qq b){
return a.a<b.a;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>x>>y;
p[++z].a=x;
p[z].b=1;
p[++z].a=x+y;
p[z].b=-1;
}
sort(p+1,p+z+1,cmp);
for(int i=1;i<=z;i++){
o[w]+=p[i].a-p[i-1].a;
w+=p[i].b;
}
for(int i=1;i<=n;i++){
cout<<o[i]<<" ";
}
}