Advertisement
sherry_ahmos

Untitled

Apr 21st, 2022
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <iomanip>
  7. #include <numeric>
  8. #include <vector>
  9.  
  10. using namespace std;
  11. #define ll long long
  12. void sherry()
  13. {
  14.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  15. #ifndef ONLINE_JUDGE
  16.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  17. #endif
  18. }
  19. int main()
  20. {
  21.  
  22.     sherry();
  23.     ll n, m, count = 0;
  24.     cin >> n >> m;
  25.     ll sum[m + 1]{}, sum2[m + 1]{};
  26.     for (ll i = 1; i <= n; i++)
  27.     {
  28.         ll a, b;
  29.         cin >> a >> b;
  30.         sum[a] += 1;
  31.         sum[b + 1] -= 1;
  32.     }
  33.     for (ll i = 1; i <= m; i++)
  34.     {
  35.         sum2[i] = sum2[i - 1] + sum[i];
  36.         if (sum2[i] == 0)
  37.             count++;
  38.     }
  39.     cout << count << "\n";
  40.     for (ll i = 1; i <= m; i++)
  41.     {
  42.         if (sum2[i] == 0)
  43.             cout << i << " ";
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement