fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int x,p,zhong;
  4. priority_queue<int,vector<int>,greater<int> >q1;
  5. priority_queue<int> q2;
  6. int main(){
  7. ios::sync_with_stdio(false);
  8. cin.tie(0),cout.tie(0);
  9. cin>>x>>p;
  10. zhong=x;
  11. for(int i=1;i<=p;i++){
  12. int a,b,sum=0;
  13. cin>>a>>b;
  14. if(a<x){
  15. q2.push(a);
  16. }else{
  17. q1.push(a);
  18. sum++;
  19. }
  20. if(b<x){
  21. q2.push(b);
  22. }else{
  23. q1.push(b);
  24. sum++;
  25. }
  26. if(sum==0){
  27. cout<<q2.top()<<"\n";
  28. q1.push(zhong);
  29. zhong=q2.top();
  30. q2.pop();
  31.  
  32. }else if(sum==2){
  33. cout<<q1.top()<<"\n";
  34. q2.push(zhong);
  35. zhong=q1.top();
  36. q1.pop();
  37. }
  38. if(sum==1){
  39. cout<<zhong<<"\n";
  40. }
  41.  
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0s 5328KB
stdin
278117031
7
167642909 517897721
148434323 567739597
319926999 481642530
659199879 252516557
49913403 798318034
89701408 892537201
199166668 742285869
stdout
278117031
278117031
319926999
319926999
319926999
319926999
319926999