题目链接

题解

比较水。。

常见套路,维护两个堆

Code

#include<bits/stdc++.h>
#define LL long long
#define RG register
using namespace std; inline int gi() {
int f = 1, s = 0;
char c = getchar();
while (c != '-' && (c < '0' || c > '9')) c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9') s = s*10+c-'0', c = getchar();
return f == 1 ? s : -s;
} priority_queue<int> p;
priority_queue<int, vector<int>, greater<int> > q;
const int N = 100010;
int a[N];
char s[10];
int main() {
int n = gi();
for (int i = 1; i <= n; i++) a[i] = gi();
sort(a+1, a+1+n);
int t = gi(), s1 = (n+1)/2, s2 = n-s1;
for (int i = 1; i <= s1; i++)
p.push(a[i]);
for (int i = s1+1; i <= n; i++)
q.push(a[i]);
while (t--) {
cin >> s;
if (s[0] == 'a') {
q.push(gi());
s2++;
if (q.top() < p.top()) {
int tmp = q.top(); q.pop();
q.push(p.top()); p.pop();
p.push(tmp);
}
if (s1 < s2) {
s2--;
s1++;
p.push(q.top());
q.pop();
}
}
else printf("%d\n", p.top());
}
return 0;
}

洛谷 [TJOI2010]中位数的更多相关文章

  1. 洛谷P1168 中位数

    题目描述 给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], A[2], …, A[2k - 1]的中位数.[color=red]即[/color] ...

  2. [洛谷P1168]中位数(Splay)/(主席树)

    Description 给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], A[2], -, A[2k - 1]的中位数.即前1,3,5,--个数的 ...

  3. 洛谷 P1168 中位数

    题目描述 给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], A[3], …, A[2k - 1]的中位数.[color=red]即[/color] ...

  4. 洛谷——P1168 中位数

    P1168 中位数 题目描述 给出一个长度为NN的非负整数序列$A_i$​,对于所有1 ≤ k ≤ (N + 1),输出$A_1, A_3, …, A_{2k - 1}A1​,A3​,…,A2k−1​ ...

  5. 洛谷—— P1168 中位数

    https://www.luogu.org/problem/show?pid=1168 题目描述 给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], ...

  6. 洛谷P1168 中位数——set/线段树

    先上一波链接 https://www.luogu.com.cn/problem/P1168 这道题我们有两种写法 第一种呢是线段树,我们首先需要将原本的数据离散化,线段树维护的信息就是区间内有多少个数 ...

  7. 洛谷 P1168 中位数(优先队列)

    题目链接 https://www.luogu.org/problemnew/show/P1168 解题思路 这个题就是求中位数,但是暴力会tle,所以我们用一种O(nlogn)的算法来实现. 这里用到 ...

  8. 洛谷P1168中位数

    传送门啦 基本思想就是二分寻找答案,然后用树状数组去维护有几个比这个二分出来的值大,然后就没有了: 数据要离散,这个好像用map也可以,但是不会: 那怎么离散呢? 我们先把a数组读入并复制给s数组,然 ...

  9. 洛谷 P3871 中位数

    ->题目链接 题解: 暴力 经鉴定,此题数据水到没朋友. #include<algorithm> #include<iostream> #include<cstdi ...

随机推荐

  1. ubuntu16.04 Mask_RCNN AlphaPose OpenPose Librealsense

    #############MaskRCNNcource activate flappbirdcd /home/luo/Desktop/MyFile/MaskRCNN/MyOwnMaskRCNN1/sa ...

  2. 浅析junit4及扩展实践

    junit框架相关源代码分析,网上已经有很多了,本篇不做过多相关解说,主要还是要自己多读相关源代码.本篇主要对自动化测试过程相关的测试用例,测试数据,测试结果结合junit做相关扩展说明. 如果要解读 ...

  3. Ubuntu14.04下安装glog

    下载原始代码编译 1. Clone Source Code  glog git clone https://github.com/google/glog 2. Install dependencies ...

  4. 468C Hack it!

    传送门 题目大意 分析 here 对于最后求p的过程我想再说一下 那个45就是最前一位分别是0~9,所以总贡献就是45乘上每一种数开头对应多少种情况 而后面的10则是他前面可以填多少不同的数对他做的贡 ...

  5. Asp.NET中把DataTable导出为Excel ,中文有乱码现象解决办法

    //DataTable为要导出的数据表   DataGrid dg = new DataGrid();                dg.DataSource = DataTable;        ...

  6. C# DateTime.ToString()的各种日期格式

    DateTime.ToString()的各种日期格式 例: ToString:2016/9/27 0:00:00 ToString("yyyy/MM/dd"):2016/09/27 ...

  7. numpy.loadtxt() 出现codecError_____ Excel 做矩阵乘法

    1) 用 numpy读入csv文件是报错 UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal m ...

  8. js-简单的作业

    作业 1 将课堂 偶数奇数和 猜数字游戏 电话银行转for循环 2 编写 “个人所得税计算器”函数 10000 计算个税的方法: 3500 以下免征 6500 3500 ~ 5000 部分 缴纳 3% ...

  9. 标准模板库使用参考——vector向量容器

    C++的STL从广义上讲分为algorithm(算法),container(容器)和iterator(迭代器)三类,包含了诸多在计算机科学领域里所常用的基本数据结构和基本算法. 在C++标准库中,ST ...

  10. ES更改参数max_result_window

    今天开发那边说翻页超过10000报错.早上来查阅官网手册,说from/size默认是10000.通过参数index.max_result_window进行控制.那么直接改这个参数即可. 1.先看看默认 ...