Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
1.3 kB
1
Indexable
void solve()
{
    int n;cin>>n;
    priority_queue<int,vector<int>,greater<int>>pq;vector<string> v;
    For(n){
        string ord;cin>>ord;
        if(ord=="insert"){
            int x;cin>>x;
            pq.push(x);
            string tmp = to_string(x);
            v.push_back(ord+" "+tmp);
        } 
        else if (ord == "removeMin"){
            if(pq.empty())
                v.push_back("insert 1");                
            else 
                pq.pop();
            v.push_back(ord);
        }
        else if(ord == "getMin"){
            int x;cin>>x;
            if(pq.empty()){
                string tmp= to_string(x); 
                v.push_back("insert "+tmp);
                pq.push(x);
            }
            else if(pq.top()!= x){
                while (!pq.empty()&&pq.top()!=x){
                    v.push_back("removeMin");
                    pq.pop();
                }
                if(pq.empty()){
                    string tmp =to_string(x);
                    v.push_back("insert "+tmp);                    
                }                
            } 
            string temp = to_string(x);
            v.push_back(ord+" "+temp) ;
        }
 
    }
    cout << v.size() << endl;
    For(v.size()){
        cout << v[i] << endl;
    } 
}
Leave a Comment