fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
  5. #define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
  6. #define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
  7. #define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
  8. #define SZ(S) ((int) ((S).size()))
  9.  
  10. #define DEBUG(x) { cout << #x << " = " << x << endl; }
  11. #define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
  12. #define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
  13.  
  14. int main() {
  15. ios :: sync_with_stdio(false); cin.tie(NULL);
  16. cout << (fixed) << setprecision(6);
  17. int n, q;
  18. while (cin >> n >> q && n) {
  19. set<int> s; FOR(i,1,n) s.insert(i);
  20. while (q--) {
  21. int l, r; cin >> l >> r;
  22. auto from = s.lower_bound(l);
  23. auto to = s.upper_bound(r);
  24. s.erase(from, to);
  25.  
  26. auto it = s.lower_bound(l);
  27. if (it == s.begin()) cout << '*' << ' ';
  28. else {
  29. --it;
  30. cout << *it << ' ';
  31. }
  32. it = s.upper_bound(r);
  33. if (it == s.end()) cout << '*' << "\n";
  34. else cout << *it << "\n";
  35. }
  36. cout << '-' << "\n";
  37. }
  38. return 0;
  39. }
  40.  
  41.  
Success #stdin #stdout 0s 3436KB
stdin
1 1
1 1
10 4
2 5
6 9
1 1
10 10
5 1
1 1
0 0
stdout
* *
-
1 6
1 10
* 10
* *
-
* 2
-