Cod sursa(job #2734060)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 31 martie 2021 12:30:03
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <bits/stdc++.h>

using namespace std;

#ifndef LOCAL

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

#define cin in
#define cout out

#endif //LOCAL

const int offset = (1 << (10 + 8));
int v[2 * offset];

void update(int poz, int val)
{
    int index = offset + poz;
    v[index] = val;
    index /= 2;

    while(index >= 1)
    {
        v[index] = min(v[index * 2], v[index * 2 + 1]);
        index /= 2;
    }
}

int getMin()
{
    return v[1];
}

int main()
{
    memset(v, 0x7f, sizeof(v));

    int n; cin >> n;

    int cntSize = 0;
    for(int i = 0; i < n; i++)
    {
        int q; cin >> q;
        
        if(q == 1)
        {
            int x; cin >> x;
            update(cntSize, x);
            cntSize += 1;
        }

        if(q == 2)
        {
            int x; cin >> x;
            update(x - 1, 0x1f1f1f1f);
        }

        if(q == 3)
        {
            cout << getMin() << '\n';
        }
    }
}