Language: C++

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<long long(n);i++)
#define N (1<<17)

long long bit[N + 1];

//初期化
void init(void){
	f(i, N + 1)bit[i] = 0;
	return;
}

//加算(k=1-n)
void add(long long k, long long x){
	while (k <= N){
		bit[k] += x;
		k += k& -k;
	}
	return;
}
//合計(1<=k<=r)
long long sum(long long r){
	long long s = 0;
	while (r > 0){
		s += bit[r];
		r -= r & -r;
	}
	return s;
}



int main(){
	long long a[N];
	vector<long long>aa;
	vector<long long>b[2 * N];
	long long c[N];
	long long d[N];
	f(i, N){
		a[i] = 0;
		c[i] = 0;
		d[i] = 0;
	}
	long long k;
	long long n;
	long long x, y, z;
	long long s, ans;
	scanf("%lld", &n);
	ans = n;
	ans = ans*(ans + 1);
	ans = ans / 2;
	ans += 2;
	ans = ans / 2;
	f(i, n){
		scanf("%lld", &a[i]);
		aa.push_back(a[i]);
	}
	sort(aa.begin(), aa.end());

	long long l = 0;
	long long r = n;
	long long  m;
	while (l + 1 < r){
		m = (l + r) / 2;
		m--;
		c[0] = 0;
		f(i, 2 * n + 1)b[i].clear();
		b[n].push_back(0);
		f(i, n){
			if (a[i] < aa[m])c[i + 1] = c[i] + 1;
			else c[i + 1] = c[i] - 1;
			b[c[i + 1] + n].push_back(i + 1);
		}
		k = 1;
		f(i, 2 * n + 1){
			f(j, b[i].size()){
				d[b[i][j]] = k;
				k++;
			}
		}
		init();
		s = 0;
		f(i, (n + 1)){
			s += sum(d[i]);
			add(d[i], 1);
		}
		if (s < ans)l = m + 1;
		else r = m + 1;
	}


	printf("%lld\n", aa[l]);


	return 0;
}


Compiler output:
a.cc: In function 'void init()':
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:20:9: note: in expansion of macro 'f'
   20 |         f(i, N + 1)bit[i] = 0;
      |         ^
a.cc:13:36: error: expected ';' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:20:9: note: in expansion of macro 'f'
   20 |         f(i, N + 1)bit[i] = 0;
      |         ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:20:9: note: in expansion of macro 'f'
   20 |         f(i, N + 1)bit[i] = 0;
      |         ^
a.cc:13:36: error: expected ')' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                   ~                ^~~~
a.cc:20:9: note: in expansion of macro 'f'
   20 |         f(i, N + 1)bit[i] = 0;
      |         ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:20:9: note: in expansion of macro 'f'
   20 |         f(i, N + 1)bit[i] = 0;
      |         ^
a.cc:20:11: error: 'i' was not declared in this scope
   20 |         f(i, N + 1)bit[i] = 0;
      |           ^
a.cc:13:49: note: in definition of macro 'f'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                                 ^
a.cc: In function 'int main()':
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:50:9: note: in expansion of macro 'f'
   50 |         f(i, N){
      |         ^
a.cc:13:36: error: expected ';' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:50:9: note: in expansion of macro 'f'
   50 |         f(i, N){
      |         ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:50:9: note: in expansion of macro 'f'
   50 |         f(i, N){
      |         ^
a.cc:13:36: error: expected ')' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                   ~                ^~~~
a.cc:50:9: note: in expansion of macro 'f'
   50 |         f(i, N){
      |         ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:50:9: note: in expansion of macro 'f'
   50 |         f(i, N){
      |         ^
a.cc:50:11: error: 'i' was not declared in this scope
   50 |         f(i, N){
      |           ^
a.cc:13:49: note: in definition of macro 'f'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:65:9: note: in expansion of macro 'f'
   65 |         f(i, n){
      |         ^
a.cc:13:36: error: expected ';' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:65:9: note: in expansion of macro 'f'
   65 |         f(i, n){
      |         ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:65:9: note: in expansion of macro 'f'
   65 |         f(i, n){
      |         ^
a.cc:13:36: error: expected ')' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                   ~                ^~~~
a.cc:65:9: note: in expansion of macro 'f'
   65 |         f(i, n){
      |         ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:78:17: note: in expansion of macro 'f'
   78 |                 f(i, 2 * n + 1)b[i].clear();
      |                 ^
a.cc:13:36: error: expected ';' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:78:17: note: in expansion of macro 'f'
   78 |                 f(i, 2 * n + 1)b[i].clear();
      |                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:78:17: note: in expansion of macro 'f'
   78 |                 f(i, 2 * n + 1)b[i].clear();
      |                 ^
a.cc:13:36: error: expected ')' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                   ~                ^~~~
a.cc:78:17: note: in expansion of macro 'f'
   78 |                 f(i, 2 * n + 1)b[i].clear();
      |                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:78:17: note: in expansion of macro 'f'
   78 |                 f(i, 2 * n + 1)b[i].clear();
      |                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:80:17: note: in expansion of macro 'f'
   80 |                 f(i, n){
      |                 ^
a.cc:13:36: error: expected ';' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:80:17: note: in expansion of macro 'f'
   80 |                 f(i, n){
      |                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:80:17: note: in expansion of macro 'f'
   80 |                 f(i, n){
      |                 ^
a.cc:13:36: error: expected ')' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                   ~                ^~~~
a.cc:80:17: note: in expansion of macro 'f'
   80 |                 f(i, n){
      |                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:86:17: note: in expansion of macro 'f'
   86 |                 f(i, 2 * n + 1){
      |                 ^
a.cc:13:36: error: expected ';' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:86:17: note: in expansion of macro 'f'
   86 |                 f(i, 2 * n + 1){
      |                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:86:17: note: in expansion of macro 'f'
   86 |                 f(i, 2 * n + 1){
      |                 ^
a.cc:13:36: error: expected ')' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                   ~                ^~~~
a.cc:86:17: note: in expansion of macro 'f'
   86 |                 f(i, 2 * n + 1){
      |                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:86:17: note: in expansion of macro 'f'
   86 |                 f(i, 2 * n + 1){
      |                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:94:17: note: in expansion of macro 'f'
   94 |                 f(i, (n + 1)){
      |                 ^
a.cc:13:36: error: expected ';' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:94:17: note: in expansion of macro 'f'
   94 |                 f(i, (n + 1)){
      |                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:94:17: note: in expansion of macro 'f'
   94 |                 f(i, (n + 1)){
      |                 ^
a.cc:13:36: error: expected ')' before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                   ~                ^~~~
a.cc:94:17: note: in expansion of macro 'f'
   94 |                 f(i, (n + 1)){
      |                 ^
a.cc:13:36: error: expected primary-expression before 'long'
   13 | #define f(i,n) for(long long i=0;i<long long(n);i++)
      |                                    ^~~~
a.cc:94:17: note: in expansion of macro 'f'
   94 |                 f(i, (n + 1)){
      |                 ^