Cod sursa(job #1947668)

Utilizator DobosDobos Paul Dobos Data 31 martie 2017 09:56:13
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <bits/stdc++.h>
#define NMAX 200005

using namespace std;

ifstream fin ("heapuri.in");
ofstream fout ("heapuri.out");


int H[NMAX],P[NMAX],N;

void percolate(int k){
    int key = H[k],poz = P[k];

    while(k > 1 && H[k] > H[(k >> 1)]){
        K[k] =  H[(k >> 1)];
        P[k] =  P[(k >> 1)];
        k = k >> 1;
    }

    H[k] = key;
    P[k] = poz;

}


int main()
{
    ios :: sync_with_stdio(false);

    int n,t,x,k = 0;

    fin >> n;

    while(n--){
        fin >> t;

        if(t == 1){
            fin >> x;
            H[N++] = x;
            P[N] = N;
            percolate(N);
        }
        if(t == 2){
            fin >> x;
            H[p[x]] = H[N];
            P[N] = P[x];
        }
        if(t == 3)
            fout << H[1] << "\n";
    }


    cout << "Hello world!" << endl;
    return 0;
}