Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

typedef pair<ll. pll> plll;

template<class V, int ME> class BIT {
public:
    V bit[1<<ME];
    V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
    void add(int e, V val) {e++; while(e<=1<<ME) bit[e-1]+=val,e+=e&-e;}
};

BIT<ll, 18> bit1, bit2;
const ll MA = (1ll << 18);

map<ll,ll> zip;
ll unzip[MAP];

ll compress(vector<ll> &x) {
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    for(ll i = 0; i < x.size(); i++){
        zip[x[i]] = i;
        unzip[i] = x[i];
    }
    return x.size();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i, MA-1) bit1.bit[i] = 0, bit2.bit[i] = 0;

    ll Q:
    cin >> Q;
    vector<plll> queries;
    vector<ll> as;
    REP(i, Q){
    	ll q;
    	cin >> q;
    	if(q == 1){
    		ll a, b;
    		cin >> a >> b;
    		as.push_back(a);
    		queries.push_back({1, {a, b}});
    	}else{
    		queries.push_back({2, {-1, -1}});
    	}
    }
    compress(as);

    ll B = 0;
    ll cnt = 0;
    REP(i, Q){
    	auto query = queries[i];
    	if(query.first == 1){
    		ll a = query.second.first;
    		ll b = query.second.second;
    		B += b;
    		ll a_comp = zip[a];
    		bit1.add(a_comp, 1);
    		bit2.add(a_comp, a);
    		cnt++;
    	}else{
    		ll lb = -1, ub = MA; //?
    		while(ub-lb>1){
    			ll mid = (lb+ub)/2;
    			bool ok;
    			ll sum = bit1.total(mid);
    			ok = (sum >= (cnt+1)/2);
    			if(ok){
    				ub = mid;
    			}else{
    				lb = mid;
    			}
    		}
    		ll med = ub;

    		ll res = 0;
    		res -= bit2.total(med);
    		res += med * bit1.total(med);

    		res += (bit2.total(MA) - bit2.total(med));
    		res -= med * (bit1.total(MA) - bit1.total(med));

    		res += B;
    		
    		cout << res << endl;
    	}
    }
    return 0;
}

Compiler output:
a.cc:26:21: error: wrong number of template arguments (1, should be 2)
   26 | typedef pair<ll. pll> plll;
      |                     ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:89:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
   89 |     struct pair;
      |            ^~~~
a.cc:39:10: error: 'MAP' was not declared in this scope; did you mean 'MA'?
   39 | ll unzip[MAP];
      |          ^~~
      |          MA
a.cc: In function 'll compress(std::vector<long long int>&)':
a.cc:46:9: error: 'unzip' was not declared in this scope; did you mean 'zip'?
   46 |         unzip[i] = x[i];
      |         ^~~~~
      |         zip
a.cc: In function 'int main()':
a.cc:57:9: error: found ':' in nested-name-specifier, expected '::'
   57 |     ll Q:
      |         ^
      |         ::
a.cc:57:8: error: 'Q' has not been declared
   57 |     ll Q:
      |        ^
a.cc:58:9: error: qualified-id in declaration before '>>' token
   58 |     cin >> Q;
      |         ^~
a.cc:61:12: error: 'Q' was not declared in this scope
   61 |     REP(i, Q){
      |            ^
a.cc:10:37: note: in definition of macro 'REP'
   10 | #define REP(i,n) for(int i=0;i<(int)n;++i)
      |                                     ^
a.cc:68:34: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   68 |                 queries.push_back({1, {a, b}});
      |                 ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:70:34: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   70 |                 queries.push_back({2, {-1, -1}});
      |                 ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:77:12: error: 'Q' was not declared in this scope
   77 |     REP(i, Q){
      |            ^
a.cc:10:37: note: in definition of macro 'REP'
   10 | #define REP(i,n) for(int i=0;i<(int)n;++i)
      |                                     ^
a.cc:79:18: error: request for member 'first' in 'query', which is of non-class type 'int'
   79 |         if(query.first == 1){
      |                  ^~~~~
a.cc:80:30: error: request for member 'second' in 'query', which is of non-class type 'int'
   80 |                 ll a = query.second.first;
      |                              ^~~~~~
a.cc:81:30: error: request for member 'second' in 'query', which is of non-class type 'int'
   81 |                 ll b = query.second.second;
      |                              ^~~~~~