1 条题解

  • 0
    @ 2023-1-9 11:28:46

    考虑对顶堆。最矮的 BiB_i 个用大根堆 q1q_1 维护,其余的用小根堆 q2q_2 维护。随着时间推移递推。

    1. 处理一个询问后,q1q_1 扩容,不断将 q2q_2 的根 push 进 q1q_1 里;
    2. 时间戳推移,每来一个人 push 进 q1q_1,如果 q1q_1 超额了就把根 push 进 q2q_2 里;
    3. 询问就输出 q1q_1 的根。

    注意要开 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
    上传者