Luogu P1168 中位数 题解
题解 中位数 Luogu
2023-06-13 09:12:49 时间
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
#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;
}
相关文章
- 剑指Offer题解 - Day8
- 剑指Offer题解 - Day35
- 【题解】麦森数(高精度计算)
- 【题解】递归数列
- AT2153 [ARC064B] An Ordinary Game 题解
- Luogu P3054 [USACO12OPEN]跑圈Running Laps 题解
- bzoj 1858. [Scoi2010]序列操作 题解
- Codeforces Gym 101002 H. Jewel Thief 题解
- 「NOIP模拟赛」欧拉口算 题解
- Luogu P4124 [CQOI2016]手机号码 题解
- bzoj 4491. 我也不知道题目名字是什么 题解
- 【题解】Subsequence Permutation
- 【题解】Gregor and the Pawn Game
- 【题解】Planning(起飞计划)