fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MaxN=2e5;
  5. const int MaxT=2e5;
  6. int add[MaxT+1]={};
  7. struct LINE{
  8. int s, e;
  9. LINE(int s=0,int e=0):s(s),e(e){}
  10. };
  11. int main() {
  12. int N,S,T;
  13. cin>>N;
  14. for(int n=0;n<N;n++){
  15. cin>>S>>T;
  16. add[S]+=1;
  17. add[T]-=1;
  18. }
  19.  
  20. vector<LINE> ans;
  21. int now=0;
  22. for(int t=1;t<=MaxT;t++){
  23. if(now==0 && now+add[t]>0)
  24. ans.push_back(LINE(t));
  25. if(now>0 && now+add[t]==0)
  26. ans.back().e=t;
  27. now+=add[t];
  28. }
  29. for(LINE one:ans)
  30. cout<<one.s<<" "<<one.e<<"\n";
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5312KB
stdin
3
10 20
20 30
40 50
stdout
10 30
40 50