优先队列只过了两个点其他全部wa
查看原帖
优先队列只过了两个点其他全部wa
1233392
RY111楼主2024/7/17 11:22

只过了第一个和测试十二

#include<bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    priority_queue<int, vector<int>, greater<int>> q; // 最小堆
    int n;
    cin >> n; // 输入操作数
    
    while (n--) {
        int x;
        cin >> x; // 输入操作类型
        if (x == 1) {
            int y;
            cin >> y; // 输入要插入的元素
            q.push(y); // 将元素插入到最小堆中
        } else if (x == 2) {
            if (!q.empty()) {
                cout << q.top() << endl; // 输出最小堆中的最小元素
                q.pop(); // 弹出最小堆中的最小元素
            } 
        } else if (x == 3) {
            if (!q.empty()) {
                q.pop(); // 弹出最小堆中的最小元素
            } 
        }
    }
    
    return 0;
}
2024/7/17 11:22
加载中...