Language: C++

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <map>
#include <memory.h>
#include <queue>
#include <string.h>
#include <set>
#include <bitset>
using namespace std;

#define ll long long
#define N 200005

int type[N];
int a[N],b[N];

ll cc[N],sum[N];

void update(ll *pen,int ind,ll val) {
  while(ind<N) {
    pen[ind] += val;
    ind += ind&(-ind);
  }
}

ll val[N];
ll query(ll *pen,int ind) {
  ll ret = 0;
  while(ind>0) {
    ret += pen[ind];
    ind = ind&(ind-1);
  }
  return ret;
}
void solve() {
  int Q;scanf("%d ", &Q);
  map<int,int> Hash;
  for(int i=0;i<Q;++i) {
    scanf("%d ", &type[i]);
    if(type[i]==1) {
      scanf("%d %d ", &a[i],&b[i]);
      Hash[a[i]];
    }
  }
  int pos=0;
  for(map<int,int>::iterator it = Hash.begin();it!= Hash.end();++it) {
    it->second = ++pos;
    val[pos] = it->first;
  }
  long long sumOfB = 0;
  int numTypeOne = 0;
  set<int> s;
  for(int i=0;i<Q;++i) {
    if(type[i]==1) {
      sumOfB += b[i];
      int aId = Hash[a[i]];
      update(cc,aId,1);
      update(sum,aId,a[i]);
      s.insert(a[i]);
      ++numTypeOne;
    } else {
      int l = 1 , r= pos,mid;
      while(l<r) {
        mid = (l+r)/2;
        if(query(cc,mid)*2>numTypeOne) {
          r = mid;
        } else {
          l = mid+1;
        }
      }
      ll R = 4e18;ll k=1e18;
      set<int>::iterator it = s.lower_bound(val[l]);
      if(it!=s.end()) {
        int cc = 2;
        while(cc>0 && it!= s.end()) {
          ll v = *it;
          long long j = Hash[*it];
          ll numLow = query(cc,j),sumLow = query(sum,j);
          ll numHigh = numTypeOne-numLow, sumHigh = query(sum,N-1) - sumLow;
          ll tmp = numLow*v - sumLow + sumHigh - numHigh*v;
          if(R>=tmp) {
            if(R==tmp) {
              k = min(k,v);
            }
            R = tmp;
          }
          --cc;
          ++it;
        }
      }
      it = s.lower_bound(val[i]);
      if(it!=s.begin()) {
        --it;
        int cc = 2;
        while(cc>0 ) {
          ll v = *it;
          int j = Hash[*it];
          ll numLow = query(cc,j),sumLow = query(sum,j);
          ll numHigh = numTypeOne-numLow, sumHigh = query(sum,N-1) - sumLow;
          ll tmp = numLow*v - sumLow + sumHigh - numHigh*v;
          if(R>=tmp) {
            if(R==tmp) {
              k = min(k,v);
            }
            R = tmp;
          }
          if(it==s.begin()) {
            break;
          }
          --cc;
          --it;
        }
      }
      printf("%lld %lld\n",k, R + sumOfB);
    }
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:81:29: error: invalid conversion from 'int' to 'long long int*' [-fpermissive]
   81 |           ll numLow = query(cc,j),sumLow = query(sum,j);
      |                             ^~
      |                             |
      |                             int
a.cc:30:14: note:   initializing argument 1 of 'long long int query(long long int*, int)'
   30 | ll query(ll *pen,int ind) {
      |              ^
a.cc:101:29: error: invalid conversion from 'int' to 'long long int*' [-fpermissive]
  101 |           ll numLow = query(cc,j),sumLow = query(sum,j);
      |                             ^~
      |                             |
      |                             int
a.cc:30:14: note:   initializing argument 1 of 'long long int query(long long int*, int)'
   30 | ll query(ll *pen,int ind) {
      |              ^