Language: C++

#include "bits/stdc++.h"
#define esc(ret) cout << (ret) << endl,quick_exit(0)
#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define repD(i,s,t) for(int i = (int)(s); i >= (int)(t); --i)
#define rep(i,n) repU(i,0,(n) - 1)
#define rep1(i,n) repU(i,1,(n))
#define all(v) begin(v),end(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define qceil(n,d) ((n) > 0 ? ((n) - 1) / (d) + 1 : (n) / (d))
#define parity(a,b) (a & 1 ^ b & 1 ^ 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;

const pii dir[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int mod = 1e9 + 7;
const int inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;

template<class Abel> struct BItree {
	int range;
	vector<Abel> data_;
	
	BItree(int size_,Abel init = 0) : range(size_ + 1)
	{
		init(int ranze);
	}
	
	void init(int n) {
		data_assign(n,0);
	}
	
	Abel sum(int r) {
		Abel s = 0;
		while (r) {
			s += data_[r];
			r -= r & -r;
		}
		return s;
	}
	
	Abel sum(int l, int r) { return sum(r) - sum(l - 1); }
	
	void add(int idx, Abel diff) {
		while (idx < range) {
			data_[idx] += diff;
			idx += idx & -idx;
		}
	}
	
	bool update(int idx, Abel val){
		int prev = sum(idx, idx);
		add(idx, val - prev);
		return val > prev;
	}
	
	int lower_bound(Abel obj){
		int lower = 0;
		int upper = range;
		while(upper - lower > 1){
			int mid = (lower + upper)/2;
			if(sum(mid) < obj) lower = mid;
			else upper = mid;
		}
		return upper;
	} 
	
	int upper_bound(Abel obj){
		int lower = 0;
		int upper = range;
		while(upper - lower > 1){
			int mid = (lower + upper)/2;
			if(sum(mid) > obj) upper = mid;
			else lower = mid;
		}
		return upper;
	} 
};



ll N,M,Q,K,L;
string S;
int a[100010],tmp[100010],s[100010];

bool ch(int x){
	rep(i,N) tmp[i] = 2 * (x <= a[i]) - 1;
	BItree<int> bt(N * 2 + 2);
	ll cnt = 0;
	s[0] = 0;
	bt.add(N + 1,1);
	rep(i,N) s[i + 1] = s[i] + tmp[i],cnt += bt.sum(N + 1 + s[i + 1]),bt.add(N + 1 + s[i + 1],1);
	return cnt >= (N * (N + 1) / 2 + 1) / 2;
}

int solve(){
	int l = 0;
	int r = inf32;
	while(r - l > 1){
		int m = (l + r) / 2;
		if(ch(m)) l = m;
		else r = m;
	}
	return l;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N;
	rep(i,N) cin >> a[i];
	cout << solve() << endl;
}






Compiler output:
a.cc: In constructor 'BItree<Abel>::BItree(int, Abel)':
a.cc:42:22: error: expected primary-expression before 'int'
   42 |                 init(int ranze);
      |                      ^~~
a.cc: In member function 'void BItree<Abel>::init(int)':
a.cc:46:17: error: there are no arguments to 'data_assign' that depend on a template parameter, so a declaration of 'data_assign' must be available [-fpermissive]
   46 |                 data_assign(n,0);
      |                 ^~~~~~~~~~~
a.cc:46:17: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc: In instantiation of 'BItree<Abel>::BItree(int, Abel) [with Abel = int]':
a.cc:104:26:   required from here
  104 |         BItree<int> bt(N * 2 + 2);
      |                                 ^
a.cc:42:31: error: 'init' cannot be used as a function
   42 |                 init(int ranze);
      |                               ^