1 条题解
-
0
考虑对顶堆。最矮的 个用大根堆 维护,其余的用小根堆 维护。随着时间推移递推。
- 处理一个询问后, 扩容,不断将 的根 push 进 里;
- 时间戳推移,每来一个人 push 进 ,如果 超额了就把根 push 进 里;
- 询问就输出 的根。
注意要开
unsigned int
。#include <cstdio> #include <queue> using namespace std; priority_queue<unsigned> q1; priority_queue<unsigned, vector<unsigned>, greater<unsigned> > q2; unsigned a[300005]; int main() { int n, m, pos = 0; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%u", &a[i]); for (int i = 1; i <= m; i++) { int b; scanf("%d", &b); while (q1.size() < i && !q2.empty()) q1.push(q2.top()), q2.pop(); while (pos < b) { q1.push(a[++pos]); if (q1.size() > i) q2.push(q1.top()), q1.pop(); } printf("%u\n", q1.top()); } return 0; }
- 1
信息
- ID
- 5
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者