Language: C++

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 100005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int N;
int A[SIZE];
int S[SIZE];
vector<int> a,t;

int bit[SIZE];
int sum(int i){
	int s = 0;
	while(i>0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i,int x){
	while(i <= N){
		bit[i] += x;
		i += i & -i;
	}
}

int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%d",&A[i]);
		a.push_back(A[i]);
	}
	int num = N*(N+1)/2;
	num = (num+1)/2;
	sort(a.begin(),a.end());
	a.erase(unique(a.begin(),a.end()),a.end());
	int l=0,r=a.size();
	while(r-l>1){
		int m = (l+r)/2;
		map<int,int> M;
		S[0] = 0;
		for(int i=1;i<=N;i++){
			S[i] = S[i-1] + (A[i]>=a[m]?1:-1);
			t.push_back(S[i]);
			//printf("%d,",S[i]);
		}
		t.push_back(0);
		sort(t.begin(),t.end());
		t.erase(unique(t.begin(),t.end()),t.end());
		for(int i=0;i<t.size();i++){
			M[t[i]] = i+1;
		}
		for(int i=0;i<=N;i++){
			//printf("%d,",M[S[i]]);
			S[i] = M[S[i]];
		}
		int ans=0;
		for(int i=0;i<=N;i++){
			ans += sum(S[i]);
			add(S[i],1);
		}
		//printf(":%d,%d\n",a[m],ans);
		if(ans >= num)l = m;
		else r = m;
		for(int i=1;i<=N+1;i++){
			bit[i] = 0;
		}
	}
	printf("%d\n",a[l]);
	//printf("%d\n",l);
	return 0;
}
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 100005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int N;
int A[SIZE];
int S[SIZE];
vector<int> a,t;

int bit[SIZE];
int sum(int i){
	int s = 0;
	while(i>0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i,int x){
	while(i <= N){
		bit[i] += x;
		i += i & -i;
	}
}

int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%d",&A[i]);
		a.push_back(A[i]);
	}
	int num = N*(N+1)/2;
	num = (num+1)/2;
	sort(a.begin(),a.end());
	a.erase(unique(a.begin(),a.end()),a.end());
	int l=0,r=a.size();
	while(r-l>1){
		int m = (l+r)/2;
		map<int,int> M;
		S[0] = 0;
		for(int i=1;i<=N;i++){
			S[i] = S[i-1] + (A[i]>=a[m]?1:-1);
			t.push_back(S[i]);
			//printf("%d,",S[i]);
		}
		t.push_back(0);
		sort(t.begin(),t.end());
		t.erase(unique(t.begin(),t.end()),t.end());
		for(int i=0;i<t.size();i++){
			M[t[i]] = i+1;
		}
		for(int i=0;i<=N;i++){
			//printf("%d,",M[S[i]]);
			S[i] = M[S[i]];
		}
		int ans=0;
		for(int i=0;i<=N;i++){
			ans += sum(S[i]);
			add(S[i],1);
		}
		//printf(":%d,%d\n",a[m],ans);
		if(ans >= num)l = m;
		else r = m;
		for(int i=1;i<=N+1;i++){
			bit[i] = 0;
		}
	}
	printf("%d\n",a[l]);
	//printf("%d\n",l);
	return 0;
}


Compiler output:
a.cc:106:5: error: redefinition of 'int N'
  106 | int N;
      |     ^
a.cc:19:5: note: 'int N' previously declared here
   19 | int N;
      |     ^
a.cc:107:5: error: redefinition of 'int A [100005]'
  107 | int A[SIZE];
      |     ^
a.cc:20:5: note: 'int A [100005]' previously declared here
   20 | int A[SIZE];
      |     ^
a.cc:108:5: error: redefinition of 'int S [100005]'
  108 | int S[SIZE];
      |     ^
a.cc:21:5: note: 'int S [100005]' previously declared here
   21 | int S[SIZE];
      |     ^
a.cc:109:13: error: redefinition of 'std::vector<int> a'
  109 | vector<int> a,t;
      |             ^
a.cc:22:13: note: 'std::vector<int> a' previously declared here
   22 | vector<int> a,t;
      |             ^
a.cc:109:15: error: redefinition of 'std::vector<int> t'
  109 | vector<int> a,t;
      |               ^
a.cc:22:15: note: 'std::vector<int> t' previously declared here
   22 | vector<int> a,t;
      |               ^
a.cc:111:5: error: redefinition of 'int bit [100005]'
  111 | int bit[SIZE];
      |     ^~~
a.cc:24:5: note: 'int bit [100005]' previously declared here
   24 | int bit[SIZE];
      |     ^~~
a.cc:112:5: error: redefinition of 'int sum(int)'
  112 | int sum(int i){
      |     ^~~
a.cc:25:5: note: 'int sum(int)' previously defined here
   25 | int sum(int i){
      |     ^~~
a.cc:121:6: error: redefinition of 'void add(int, int)'
  121 | void add(int i,int x){
      |      ^~~
a.cc:34:6: note: 'void add(int, int)' previously defined here
   34 | void add(int i,int x){
      |      ^~~
a.cc:128:5: error: redefinition of 'int main()'
  128 | int main()
      |     ^~~~
a.cc:41:5: note: 'int main()' previously defined here
   41 | int main()
      |     ^~~~