Language: C++

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

typedef long long ll;
typedef pair<int, int> pii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}

//--------------------------------------------------//
map<int, int> mp
int partition(int arr[], int l, int r, int k); ;
int findMedian(int arr[], int n) {
  sort(arr, arr + n);  // Sort the array
  return arr[n / 2];   // Return middle element
}

int kthSmallest(int arr[], int l, int r, int k) {
  // If k is smaller than number of elements in array
  if (k > 0 && k <= r - l + 1) {
    int n = r - l + 1;  // Number of elements in arr[l..r]

    // Divide arr[] in groups of size 5, calculate median
    // of every group and store it in median[] array.
    int i, median[(n + 4) / 5];  // There will be floor((n+4)/5) groups;
    for (i = 0; i < n / 5; i++)
      median[i] = findMedian(arr + l + i * 5, 5);
    if (i * 5 < n)  //For last group with less than 5 elements
    {
      median[i] = findMedian(arr + l + i * 5, n % 5);
      i++;
    }

    // Find median of all medians using recursive call.
    // If median[] has only one element, then no need
    // of recursive call
    int medOfMed = (i == 1) ? median[i - 1] : kthSmallest(median, 0, i - 1, i / 2);

    // Partition the array around a random element and
    // get position of pivot element in sorted array
    int pos = partition(arr, l, r, medOfMed);

    // If position is same as k
    if (pos - l == k - 1)
      return arr[pos];
    if (pos - l > k - 1)  // If position is more, recur for left
      return kthSmallest(arr, l, pos - 1, k);

    // Else recur for right subarray
    return kthSmallest(arr, pos + 1, r, k - pos + l - 1);
  }

  // If k is more than number of elements in array
  return INT_MAX;
}

void swap(int *a, int *b) {
  int temp = *a;
  *a = *b;
  *b = temp;
}

// It searches for x in arr[l..r], and partitions the array
// around x.
int partition(int arr[], int l, int r, int x) {
  // Search for x in arr[l..r] and move it to end
  int i;
  for (i = l; i < r; i++)
    if (arr[i] == x)
      break;
  swap(&arr[i], &arr[r]);

  // Standard partition algorithm
  i = l;
  for (int j = l; j <= r - 1; j++) {
    if (arr[j] <= x) {
      swap(&arr[i], &arr[j]);
      i++;
    }
  }
  swap(&arr[i], &arr[r]);
  return i;
}
int arr[100010];
int main() {
  use_cio();
  int q;
  cin >> q;
  vector<int> va;
  ll median = 2e9;
  ll total_b = 0;
  ll sz = 0;
  rep(i, q) {
    int tp;
    cin >> tp;
    if (tp == 1) {
      ll a, b;
      cin >> a >> b;
      mp[a]++;
      if (mp[a] == 1) {
        arr[sz++] = a;
      }
      total_b += b;
    } else {
      if (sz == 0) {
        cout << "0 0\n";
        continue;
      }
      median = kthSmallest(arr, 0, sz - 1, (sz - 1) / 2);
      cout << median << " ";
      ll val = 0;
      for (auto x : va) {
        val += 1LL * mp[x] * abs(median - x);
      }
      cout << val + total_b << endl;
    }
  }
}


Compiler output:
a.cc:31:1: error: expected initializer before 'int'
   31 | int partition(int arr[], int l, int r, int k); ;
      | ^~~
a.cc: In function 'int kthSmallest(int*, int, int, int)':
a.cc:60:24: error: no matching function for call to 'partition(int*&, int&, int&, int&)'
   60 |     int pos = partition(arr, l, r, medOfMed);
      |               ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:4573:5: note: candidate: 'template<class _BIter, class _Predicate> _BIter std::partition(_BIter, _BIter, _Predicate)'
 4573 |     partition(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4573:5: note:   candidate expects 3 arguments, 4 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:275:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::partition(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _UnaryPredicate)'
  275 | partition(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred);
      | ^~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:275:1: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15:
/usr/include/c++/14/pstl/execution_defs.h: In substitution of 'template<class _ExecPolicy, class _Tp> using __pstl::__internal::__enable_if_execution_policy = typename std::enable_if<__pstl::execution::v1::is_execution_policy<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value, _Tp>::type [with _ExecPolicy = int*&; _Tp = int]':
/usr/include/c++/14/pstl/glue_algorithm_defs.h:275:1:   required by substitution of 'template<class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::partition(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _UnaryPredicate) [with _ExecutionPolicy = int*&; _ForwardIterator = int; _UnaryPredicate = int]'
a.cc:60:24:   required from here
   60 |     int pos = partition(arr, l, r, medOfMed);
      |               ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/pstl/execution_defs.h:82:7: error: no type named 'type' in 'struct std::enable_if<false, int>'
   82 | using __enable_if_execution_policy =
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:118:7: error: 'mp' was not declared in this scope; did you mean 'tp'?
  118 |       mp[a]++;
      |       ^~
      |       tp
a.cc:132:22: error: 'mp' was not declared in this scope; did you mean 'tp'?
  132 |         val += 1LL * mp[x] * abs(median - x);
      |                      ^~
      |                      tp