Guest User

Untitled

a guest
May 16th, 2026
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fastio ios::sync_with_stdio(false); cin.tie(nullptr);
  5. #define all(x) (x).begin(), (x).end()
  6. #define rall(x) (x).rbegin(), (x).rend()
  7. #define pb push_back
  8.  
  9. #define ll long long
  10. #define int long long
  11.  
  12. #define f first
  13. #define s second
  14.  
  15. const int INF = 1e18;
  16. const int MOD = 1e9 + 7;
  17.  
  18. template<typename T>
  19. bool chmin(T &a, T b) {
  20.     if (a > b) { a = b; return true; }
  21.     return false;
  22. }
  23.  
  24. template<typename T>
  25. bool chmax(T &a, T b) {
  26.     if (a < b) { a = b; return true; }
  27.     return false;
  28. }
  29.  
  30. template<typename T>
  31. istream& operator>>(istream &is, vector<T> &v) {
  32.     for (auto &x : v) is >> x;
  33.     return is;
  34. }
  35.  
  36. template<typename T>
  37. ostream& operator<<(ostream &os, const vector<T> &v) {
  38.     for (auto &x : v) os << x << " ";
  39.     return os;
  40. }
  41.  
  42. #ifdef LOCAL
  43. #define dbg(x) cerr << #x << " = " << x << '\n'
  44. #else
  45. #define dbg(x)
  46. #endif
  47.  
  48. void tc() {
  49.     int x;
  50.     cin>>x;
  51.     int q;
  52.     cin>>q;
  53.     priority_queue<int>left;
  54.     priority_queue<int, vector<int>, greater<int>>right;
  55.    
  56.     left.push(x);
  57.     while(q--){
  58.         int a,b;
  59.         cin>>a>>b;
  60.         if(left.top() >= a)left.push(a);
  61.         else right.push(a);
  62.         if(left.top() >= a)left.push(b);
  63.         else right.push(b);
  64.         if(left.size() > right.size()){
  65.             while(left.size() != right.size()+1){
  66.                 right.push(left.top());
  67.                 left.pop();
  68.             }
  69.         }else{
  70.             while(left.size() != right.size()+1){
  71.                 left.push(right.top());
  72.                 right.pop();
  73.             }
  74.         }
  75.         cout<<left.top()<<"\n";
  76.     }
  77. }
  78.  
  79. int32_t main() {
  80.     fastio;
  81.  
  82.     int tt = 1;
  83.     // cin >> tt;
  84.     while (tt--) {
  85.         tc();
  86.     }
  87.  
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment