前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Luogu P1168 中位数 题解

Luogu P1168 中位数 题解

作者头像
yzxoi
发布2022-09-19 13:12:22
1750
发布2022-09-19 13:12:22
举报
文章被收录于专栏:OI

Luogu P1168 中位数 题解

Description

题目链接

给出一个长度为 N 的非负整数序列 A_i,对于所有 1 ≤ k ≤ (N + 1) / 2,输出 A_1, A_1 \sim A_3, …,A_1 \sim A_{2k - 1} ​的中位数。即前 1,3,5,… 个数的中位数。

Solution

众所周知,vector 可以当平衡树来用。

Code

代码语言:javascript
复制
#include<cstdio>
#include<vector>
const int N=100010;
int n,a[N];
std::vector<int> v;
int main(){
scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++){
v.insert(lower_bound(v.begin(),v.end(),a[i]),a[i]);
if(i&1) printf("%d\n",v[i/2]);
}
return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-10-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Luogu P1168 中位数 题解
    • Description
      • Solution
        • Code
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档