Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn(i, n) for (int i = 0; (i) < (int) (n); (i) ++)


 
//1-origin
template <typename T>
ll InversionNumber(const vector<int> &a) {
        Tree<ll> ft(300030);
        ll res = 0;
        for (int i = 0; i < a.size(); i ++) {
                res += i - ft.sum(a[i]);
                ft.add(a[i], 1);
        }
        return res;
}
struct Tree {
        vector<T> data;
        Tree(int n) : data(n + 1, 0) {}
        //data[i] += x
        void add(int i, T x){
                while (i <= (int)data.size()) {
                        data[i] += x;
                        i += i & -i;
                }
        }
        //[1, i)
        T sum(int i){
                T res = 0;
                while (i > 0) {
                        res += data[i];
                        i -= i & -i;
                }
                return res;
        }
        //[l, r)
        T sum(int l, int r) { return sum(r) - sum(l); }
};

 
int main() {
        int n;
        cin>>n;
        vector<int> a(n);
        forn(i, n) 
        {
                cin>>a[i];
        }
        ll lb = 0, ub = 1e9 + 5;
        while (ub - lb > 1) {
                ll x = (lb + ub) / 2;
                vector<int> b(n);
                forn(i, n) {
                        b[i] = a[i] >= x ? 1 : -1;
                }
                vector<int> acc(n + 1);
                for (int i = 1; i <= n; i ++) {
                        acc[i] = acc[i - 1] + b[i - 1];
                }
                forn(i, n + 1) acc[i] += 150000;
                ll res = (ll) (n + 1) * n / 2 - InversionNumber(acc);
                if (res >= ((ll) (n + 1) * n / 2 + 1) / 2) {
                        lb = x;
                } else {
                        ub = x;
                }
        }
        printf("%lld\n", lb);
        return 0;
}

Compiler output:
a.cc: In function 'll InversionNumber(const std::vector<int>&)':
a.cc:11:9: error: 'Tree' was not declared in this scope; did you mean 'free'?
   11 |         Tree<ll> ft(300030);
      |         ^~~~
      |         free
a.cc:11:16: error: expected primary-expression before '>' token
   11 |         Tree<ll> ft(300030);
      |                ^
a.cc:11:18: error: there are no arguments to 'ft' that depend on a template parameter, so a declaration of 'ft' must be available [-fpermissive]
   11 |         Tree<ll> ft(300030);
      |                  ^~
a.cc:11:18: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:14:28: error: 'ft' was not declared in this scope
   14 |                 res += i - ft.sum(a[i]);
      |                            ^~
a.cc: At global scope:
a.cc:20:16: error: 'T' was not declared in this scope
   20 |         vector<T> data;
      |                ^
a.cc:20:17: error: template argument 1 is invalid
   20 |         vector<T> data;
      |                 ^
a.cc:20:17: error: template argument 2 is invalid
a.cc:23:25: error: 'T' has not been declared
   23 |         void add(int i, T x){
      |                         ^
a.cc:30:9: error: 'T' does not name a type
   30 |         T sum(int i){
      |         ^
a.cc:39:9: error: 'T' does not name a type
   39 |         T sum(int l, int r) { return sum(r) - sum(l); }
      |         ^
a.cc: In constructor 'Tree::Tree(int)':
a.cc:21:23: error: expression list treated as compound expression in mem-initializer [-fpermissive]
   21 |         Tree(int n) : data(n + 1, 0) {}
      |                       ^~~~~~~~~~~~~~
a.cc: In member function 'void Tree::add(int, int)':
a.cc:24:39: error: request for member 'size' in '((Tree*)this)->Tree::data', which is of non-class type 'int'
   24 |                 while (i <= (int)data.size()) {
      |                                       ^~~~
a.cc:25:29: error: invalid types 'int[int]' for array subscript
   25 |                         data[i] += x;
      |                             ^
a.cc: In function 'int main()':
a.cc:63:64: error: no matching function for call to 'InversionNumber(std::vector<int>&)'
   63 |                 ll res = (ll) (n + 1) * n / 2 - InversionNumber(acc);
      |                                                 ~~~~~~~~~~~~~~~^~~~~
a.cc:10:4: note: candidate: 'template<class T> ll InversionNumber(const std::vector<int>&)'
   10 | ll InversionNumber(const vector<int> &a) {
      |    ^~~~~~~~~~~~~~~
a.cc:10:4: note:   template argument deduction/substitution failed:
a.cc:63:64: note:   couldn't deduce template parameter 'T'
   63 |                 ll res = (ll) (n + 1) * n / 2 - InversionNumber(acc);
      |                                                 ~~~~~~~~~~~~~~~^~~~~