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 val = 0) : range(size_ + 1)
	{
		init(range,val);
	}
	
	void init(int n) {
		data_.assign(n,val);
	}
	
	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 member function 'void BItree<Abel>::init(int)':
a.cc:46:32: error: 'val' was not declared in this scope
   46 |                 data_.assign(n,val);
      |                                ^~~
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:21: error: no matching function for call to 'BItree<int>::init(int&, int&)'
   42 |                 init(range,val);
      |                 ~~~~^~~~~~~~~~~
a.cc:45:14: note: candidate: 'void BItree<Abel>::init(int) [with Abel = int]'
   45 |         void init(int n) {
      |              ^~~~
a.cc:45:14: note:   candidate expects 1 argument, 2 provided