From d25daeb46690f3df713bddee993319125609a0d0 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sat, 7 Nov 2020 23:47:19 +0800 Subject: [PATCH] =?UTF-8?q?P1168=20=E4=B8=AD=E4=BD=8D=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R41500325 --- problem/P1168/P1168.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/problem/P1168/P1168.cpp b/problem/P1168/P1168.cpp index c1cac7f4..cf0cda27 100644 --- a/problem/P1168/P1168.cpp +++ b/problem/P1168/P1168.cpp @@ -1,16 +1,31 @@ -#include +#include using namespace std; int main() { - int n, t; - vector a; + int n, a[100005], k; + priority_queue, less > s; + priority_queue, greater > l; cin >> n; - for (int i = 1; i <= n; i++) { - cin >> t; - a.insert(upper_bound(a.begin(), a.end(), t), t); - if (i % 2) { - cout << a[(i - 1) / 2] << endl; + for(int i = 1 ; i <= n ; i++) { + cin >> a[i]; + k = i/2+1; + if(!l.empty() && a[i] >= l.top()) { + s.push(a[i]); + } + else { + l.push(a[i]); + } + while(l.size() < k) { + l.push(s.top()); + s.pop(); + } + while(s.size() < k) { + s.push(l.top()); + l.pop(); + } + if(i%2) { + cout << s.top() << endl; } } return 0;