fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int x,p,arr[200002];
  4. priority_queue<int,vector<int>,greater<int> >q;
  5. int main(){
  6. ios::sync_with_stdio(false);
  7. cin.tie(0),cout.tie(0);
  8. cin>>x>>p;
  9. q.push(x);
  10. for(int i=1;i<=p;i++){
  11. int a,b;
  12. cin>>a>>b;
  13. q.push(a);
  14. q.push(b);
  15. int l=q.size()/2;
  16. int op=1;
  17. while(!q.empty() && q.size()!=l+1){
  18. arr[op]=q.top();
  19. q.pop();
  20. op++;
  21. }
  22. cout<<q.top()<<"\n";
  23. for(int i=1;i<=op-1;i++){
  24. q.push(arr[i]);
  25. }
  26. }
  27. return 0;
  28. }
  29. /*
  30. 奇数个:中位数是第 (n+1)/2 个数据,例如 5 个数据取第 3 个 。
  31. o(n(n/2)
  32. 偶数个:中位数是第 n/2 个和第 (n/2+1) 个数据的平均数,例如 4 个数据取第 2、3 个的平均值 。
  33. */
Success #stdin #stdout 0.01s 5324KB
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