fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24.  
  25.  
  26. vector<vector<int>> a;
  27. void consistency(int n) {
  28.  
  29. map<int,int> events;
  30.  
  31. for(int i=0; i<n; i++){
  32. int s = a[i][0];
  33. int e = a[i][1];
  34.  
  35. events[s]++;
  36. events[e]--;
  37. }
  38.  
  39. int acc = 0;
  40. int last = -1;
  41. vector<vector<int>> ans;
  42. for(auto& e : events){
  43. if(acc == 0){
  44. last = e.first;
  45. }
  46. acc += e.second;
  47. if(acc == 0){
  48. if(last != -1) ans.push_back({last, e.first});
  49. }
  50. }
  51.  
  52. for(int i=0; i<ans.size(); i++){
  53. cout << ans[i][0] << ":" << ans[i][1] << " , ";
  54. }
  55.  
  56. }
  57.  
  58. void solve() {
  59.  
  60. int n;
  61. cin >> n;
  62.  
  63. a.resize(n);
  64. for(int i=0; i<n; i++){
  65. int x, y;
  66. cin >> x >> y;
  67. a[i] = {x,y};
  68. }
  69.  
  70. consistency(n);
  71.  
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. int32_t main() {
  79. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  80.  
  81. int t = 1;
  82. cin >> t;
  83. while (t--) {
  84. solve();
  85. }
  86.  
  87. return 0;
  88. }
Success #stdin #stdout 0.01s 5276KB
stdin
1
4
2 4
5 7
6 8
10 12
stdout
2:4 , 5:8 , 10:12 ,