fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7. long long n,q;cin>>n;
  8. multiset<int> myset;
  9. map<int ,int> freq;
  10. for (int i=0;i<n;i++)
  11. {
  12. long long num;cin>>num;
  13. myset.insert(num);
  14. freq[num]++;
  15. }
  16. cin>>q;
  17. while (q--)
  18. {
  19. long long type,x;cin>>type;
  20. if (type==1)
  21. {
  22. cin>>x;
  23. myset.insert(x);
  24. freq[x]++; n++;
  25. }
  26. else
  27. {
  28. cin>>x;
  29. if (freq[x]==0)
  30. {
  31.  
  32. }
  33. else
  34. {
  35. auto it=myset.find(x);
  36. myset.erase(it);
  37. freq[x]--;
  38. n--;
  39.  
  40. }
  41.  
  42.  
  43. }
  44. auto mid=myset.begin();
  45. auto it1 = next(mid,n/2);
  46. if (n%2==0)
  47. {
  48.  
  49.  
  50. auto it2 = prev(it1);
  51. cout<<(double)(*it1+*it2)/2<<"\n";
  52. }
  53. else
  54. {
  55. cout<<(*it1)<<"\n";
  56. }
  57. }
  58.  
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 5292KB
stdin
5 10 8 10 1 2 4 1 10 2 2 1 3 1 1
stdout
9
10
9
8