Cod sursa(job #2738185)

Utilizator armigheGheorghe Liviu Armand armighe Data 5 aprilie 2021 15:43:56
Problema Heapuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");
set<int>s;
unordered_map<int,int>m;
int v[200002];
int main()
{
    int n,i,p,x,k=0;
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>p;
        if(p==1)
        {
            f>>x;
            m[x]++;
            if(m[x]==1)
                s.insert(x);
            k++;
            v[k]=x;
        }
        else
        if(p==2)
        {
            f>>x;
            m[v[x]]--;
            if(m[v[x]]==0)
                s.erase(v[x]);
        }
        else
        {
            auto it=s.begin();
            g<<*it<<'\n';
        }
    }
    return 0;
}