mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
P1168 中位数
R41500325
This commit is contained in:
parent
45f053cad9
commit
d25daeb466
@ -1,16 +1,31 @@
|
||||
#include <bits/stdc++.h>
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n, t;
|
||||
vector<int> a;
|
||||
int n, a[100005], k;
|
||||
priority_queue<int, vector<int>, less<int> > s;
|
||||
priority_queue<int, vector<int>, greater<int> > 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;
|
||||
|
Loading…
Reference in New Issue
Block a user