2 条题解

  • 1
    @ 2025-12-7 9:29:01
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main(){
    	ios::sync_with_stdio(0);
    	cin.tie(0);
    	int n,q;
    	multiset<int> s;
    	cin>>n>>q;
    	for(int i=1,x;i<=n;i++){
    		cin>>x;
    		s.insert(x);
    	}
    	while(q--){
    		int op;
    		cin>>op;
    		if(op==0){
    			int x;
    			cin>>x;
    			s.insert(x);
    		}
    		else if(op==1){
    			auto it=s.begin();
    			cout<<*it<<'\n';
    			s.erase(it);
    		}
    		else{
    			auto it=s.end();
    			it--;
    			cout<<*it<<'\n';
    			s.erase(it);
    		}
    	}
    	return 0;
    }
    
    • 0
      @ 2026-8-3 10:27:16
      #include <bits/stdc++.h>
      using namespace std;
      typedef long long ll;
      int main()
      {
          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
          int n, q;cin >> n >> q;
          vector<int> a(n);
          
          for (auto &x : a)cin >> x;
          multiset<int> s(a.begin(), a.end());
      
          while (q--)
          {
              int op;cin >> op;
              if (op == 0)
              {
                  int x;
                  cin >> x;
                  s.insert(x);
              }
              else if (op == 1)
              {
                  auto it = s.begin();
                  cout << *it << '\n';
                  s.erase(it);
              }
              else
              {
                  auto it = s.end();
                  it--;
                  cout << *it << '\n';
                  s.erase(it);
              }
          }
          return 0;
      }
      
      
      • 1

      *【STL:multiset】双端优先队列(Double-Ended Priority Queue)

      信息

      ID
      8119
      时间
      2000ms
      内存
      1024MiB
      难度
      6
      标签
      递交数
      86
      已通过
      25
      上传者