fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void solve() {
  6. int n;
  7. if (!(cin >> n)) return;
  8.  
  9. multiset<int> s;
  10.  
  11. for (int i = 0; i < n; ++i) {
  12. int l, r;
  13. cin >> l >> r;
  14.  
  15. auto it = s.upper_bound(r);
  16.  
  17.  
  18. if (it != s.end()) {
  19. s.erase(it);
  20. }
  21.  
  22. s.insert(l);
  23.  
  24. // Rozmiar zbioru s w każdym kroku to odpowiedź dla prefiksu o długości i+1.
  25. cout << s.size() << (i == n - 1 ? "" : " ");
  26. }
  27. cout << "\n";
  28. }
  29.  
  30. int main() {
  31. // Te dwie linie są KLUCZOWE, żeby kod był szybki (wyłączają synchronizację z C)
  32. ios_base::sync_with_stdio(false);
  33. cin.tie(NULL);
  34.  
  35. int t;
  36. if (cin >> t) {
  37. while (t--) {
  38. solve();
  39. }
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty