洛谷 P1168 中位数(stl)

发布时间 2023-03-27 21:23:42作者: 高尔赛凡尔娟


vector使用insert(idx,x)表示在idx的位置上插入x这个数字
这样可以保证我们vector内的数字的有序性

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=2023;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
int n;
vector<int> v;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            int x;
            cin>>x;
            v.insert(upper_bound(v.begin(),v.end(),x),x);
            if(i%2==1)
            {
                cout<<v[(i-1)/2]<<endl;
            }
        }
    }
    return 0;
}