1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back
const ll INF = (1LL<<60);
const int MOD = 1000000007;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
out<<'('<<a.first<<','<<a.second<<')';
return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
out<<'[';
REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
out<<']';
return out;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
// Binary Indexed Tree
// 0-indexed
template <typename T>
class BIT {
private:
// データ
vector<T> bit;
// 単位元, 要素数
int neutral = 0;
// 更新クエリ, 区間クエリ
function<T(T,T)> f = [](const T l, const T r) -> T { return l+r; },
g = [](const T l, const T r) -> T { return l+r; };
public:
// 初期化
BIT(int n_ = 1e5) { init(n_); }
void init(int n_ = 1e5) { bit.assign(n_+1, neutral); }
// iに対する点更新クエリ
void update(int i, T w) {
for(int x = i+1; x < bit.size(); x += x&-x) bit[x] = f(bit[x], w);
}
// [0,i]に対する区間クエリ
T query(int i) {
T ret = neutral;
for(int x = i+1; x > 0; x -= x & -x) ret = g(ret, bit[x]);
return ret;
}
};
signed main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
V<int> a(n);
REP(i, n) cin >> a[i];
auto check = [&](int mid) -> bool {
int now = 1e5;
int ret = 0;
BIT<int> bit(2e5+10);
bit.update(now, 1);
REP(i, n) {
if(a[i] < mid) now++;
else now--;
bit.update(now, 1);
ret += bit.query(now-1);
}
int m = n*(n+1)/4 + 1;
return ret < m;
};
int lb = 0, ub = 1e9+10;
while(ub-lb > 1) {
int mid = (lb+ub)/2;
if(check(mid)) lb = mid;
else ub = mid;
}
cout << lb << endl;
return 0;
}
|