洛谷 P1168 中位数(stl)
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;
}
本文作者:Vivian-0918
本文链接:https://www.cnblogs.com/Vivian-0918/p/17262941.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
stl
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步