Cod sursa(job #1146675)

Utilizator swim406Teudan Adina swim406 Data 19 martie 2014 10:45:56
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.96 kb
#include <stdio.h>
#include <set>
#define NMAX 200005

using namespace std;

set <int> H;
int numar[NMAX], NR;

/*int H[NMAX], pos[NMAX], L, val[NMAX], NR;

void minim() {
    //printf ("%d\n", val[H[1]]);
    for (int i = 1; i <= L; ++i)
        printf ("%d ", val[H[i]]);
    printf ("\n");
}

void insert() {
    int x, aux;
    scanf ("%d", &x);
    val[++NR] = x;
    pos[NR] = ++L;
    H[L] = NR;
    x = L;
    while (x/2 && val[H[x/2]] > val[H[x]]) {
        aux = H[x/2];
        H[x/2] = H[x];
        H[x] = aux;
        pos[H[x/2]] = x/2;
        pos[H[x]] = x;
        x /= 2;
    }
}

void order() {
    int x, y, aux;
    scanf ("%d", &x);
    val[x] = -1;
    x = pos[x];
    while (x/2 && val[H[x/2]] > val[H[x]]) {
        aux = H[x/2];
        H[x/2] = H[x];
        H[x] = aux;
        pos[H[x/2]] = x/2;
        pos[H[x]] = x;
        x /= 2;
    }
    pos[H[1]] = 0;
    H[1] = H[L];
    pos[H[1]] = 1;
    --L;
    x = 1;
    y = 0;
    if (L > 1)
        while (x != y) {
            y = x;
            if (2*x <= L && val[H[x]] > val[H[2*x]]) x = y*2;
            if (2*x + 1 <= L && val[H[x]] > val[H[2*x+1]]) x = y*2+1;
            aux = H[x];
            H[x] = H[y];
            H[y] = aux;
            pos[H[y]] = y;
            pos[H[x]] = x;
        }

}
*/

int main() {
    freopen ("heapuri.in", "r", stdin);
    freopen ("heapuri.out", "w", stdout);
    int N, opt, x;
    scanf ("%d", &N);
    while (N--) {
        scanf ("%d", &opt);
        switch (opt) {
            case 1: {
                scanf ("%d", &x);
                H.insert(x);
                numar[++NR] = x;
                break;
            }
            case 2: {
                scanf ("%d", &x);
                H.erase(numar[x]);
                break;
            }
            case 3: {
                printf ("%d\n", *H.begin());
                break;
            }
        }
    }
    return 0;
}