Cod sursa(job #2738189)

Utilizator armigheGheorghe Liviu Armand armighe Data 5 aprilie 2021 15:45:36
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.55 kb
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast")
using namespace std;
ofstream g("heapuri.out");
class InputReader {
  private:
    static const int BUFF_SIZE = 100000;
    FILE *f;
    int bp;
    char buff[BUFF_SIZE];
    inline void nxt() {
      if (++bp == BUFF_SIZE) {
        fread(buff, sizeof(char), BUFF_SIZE, f);
        bp = 0;
      }
    }
  public:
    InputReader (const char *file_name) {
      f = fopen(file_name, "r");
      bp = BUFF_SIZE - 1;
    }
    void close() {
      fclose(f);
    }
    InputReader& operator >> (int &num) {
      num = 0;
      while (isdigit(buff[bp]) == 0&&buff[bp]!='-')
        nxt();
      int semn=1;
      if(buff[bp]=='-')
      {
        semn=-1;
        nxt();
      }
      while (isdigit(buff[bp])) {
        num = num * 10 + (buff[bp] - '0')*semn;
        nxt();
      }
      return *this;
    }
} f("heapuri.in");
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;
}