题解 P1168 【中位数】

luogu

思路

第一眼对顶堆,看了题解之后。。。
思路是用lower_bound插入,保证单调性

代码

#include <bits/stdc++.h>
using namespace std;
int n,ip;
vector<int>a;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&ip);
        a.insert(lower_bound(a.begin(),a.end(),ip),ip);
        if(i%2)
        {
            cout<<a[(i-1)/2]<<endl;
        }
    }
}
posted @ 2019-07-15 10:47  G_A_TS  阅读(411)  评论(0编辑  收藏  举报