src2020/2769_qujian/main.cpp

49 lines
983 B
C++
Raw Normal View History

2020-05-02 09:30:58 +08:00
#include <iostream>
using namespace std;
int a[1000001]={0};
int q[1000001]={0};
bool ce[1000001]={0};
int main()
{
int n,end=0;
cin>>n;
for(int i=1;i<=n;i++){
int tou,wei;
cin>>tou>>wei;
if(tou==wei){
ce[tou]=1;
}
a[tou]++;
a[wei]--;
if(wei>end){
end=wei;
}
}
// for(int i=1;i<=n;i++){
// q[i]=a[i]+q[i-1];
// cout<<q[i]<<" ";
// }
// cout<<endl;
bool qi=0;
for(int i=1;i<=end;i++){
a[i]+=a[i-1];
if(qi==0&&a[i]>=1&&a[i-1]==0){
ce[i]=0;
cout<<i<<" ";
qi=1;
}
if(qi==1&&a[i]==0&&a[i-1]>0){
ce[i]=0;
cout<<i<<endl;
qi=0;
}
if(ce[i]==1&&a[i]==0){
if(qi==0){
cout<<i<<" ";
}
cout<<i<<endl;
qi=0;
}
}
}