题解:AT_arc129_b [ARC129B] Range Point Distance
题目概括
请问在前
思路
因为是前
记录下左端点最大的数,记为
记录下右端点最小的数,记为
分类讨论,如果
如果
代码(很简洁)
#include<bits/stdc++.h>
using namespace std;
int n,mi=INT_MAX,ma=INT_MIN;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int a,b;
scanf("%d%d",&a,&b);
ma=max(ma,a);//左端点最大的数
mi=min(mi,b);//右端点最小的数
if(ma<=mi){//在 l 和 r 中间
cout<<0<<endl;
}else{//在左端点左边或在右端点右边
cout<<(ma-mi+1)/2<<endl;
}
}
return 0;
}