Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize ("O3")
- #pragma GCC target ("sse4")
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef pair<string,int> psi;
- typedef unordered_map<int,int> mii;
- typedef unordered_map<long long,long long> mll;
- typedef unordered_map<string,int> msi;
- typedef unordered_map<char,int> mci;
- typedef unordered_set<int> si;
- typedef unordered_set<long long> sll;
- typedef unordered_set<string> ss;
- typedef unordered_set<char> sc;
- typedef map<int,int> ormii;
- typedef map<long long,long long> ormll;
- typedef map<string,int> ormsi;
- typedef map<char,int> ormci;
- typedef set<int> orsi;
- typedef set<long long> orsll;
- typedef set<string> orss;
- typedef set<char> orsc;
- typedef vector<int> vi;
- typedef vector<string> vs;
- typedef vector<char> vc;
- typedef vector<ll> vll;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<string>> vvs;
- typedef vector<vector<ll>> vvll;
- #define FOR(i, a, b) for (auto i=a; i<=(b); i++)
- #define FORd(i,b,a) for (int i =b; i >= a; i--)
- #define sortinc(v) sort(v.begin(),v.end())
- #define sortdec(v) sort(v.rbegin(),v.rend())
- #define sz(x) (int)(x).size()
- #define mp make_pair
- #define pb push_back
- #define pob pop_back
- #define pf push_front
- #define pof pop_front
- #define fi first
- #define se second
- #define ins insert
- const int MOD = 1000000007;
- //type functions here
- class minHeap
- {
- public:
- vi v;
- void getMin()
- {
- if(sz(v)==0) cout<<"Empty"<<endl;
- else cout<<v[0]<<endl;
- }
- void insert(int data)
- {
- v.pb(data);
- int i=sz(v)-1;
- int parent=(i-1)/2;
- while(parent>(-1))
- {
- if(v[parent]>v[i]){swap(v[i],v[parent]);i=parent;parent=(i-1)/2;}
- else break;
- }
- }
- void delMin()
- {
- if(sz(v)<=1) v={};
- else{
- v[0]=v[sz(v)-1];
- v.pop_back();
- int i=0;
- int LC=2*i+1;
- int RC=2*i+2;
- int sizee=sz(v);
- while(RC<sizee||LC<sizee)
- {
- int child=LC;
- if(RC<sizee) child=(v[LC]<=v[RC])?LC:RC;
- if(v[i]>v[child]){swap(v[i],v[child]);i=child;LC=2*i+1;RC=2*i+2;}
- else break;
- }
- }
- }
- };
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- minHeap m;
- int tc=1;
- cin>>tc;
- FOR(w,1,tc)
- {
- string s;
- cin>>s;
- char op=s[0];
- switch(op)
- {
- case 'i':{int temp;cin>>temp;m.insert(temp);};break;
- case 'g':m.getMin();break;
- case 'd':m.delMin();break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement