Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- int n = 100000, gdN;
- struct tree{
- vector <pii> v;
- void bld(){
- int gdpow = log2(n);
- if (pow(2, gdpow) < n){
- gdpow++;
- }
- gdN = pow(2, gdpow);
- v.assign(2*gdN-1, {0,0});
- //{число, кол-во чисел}
- }
- void ch(int x){
- int id = gdN - 2 + x;
- v[id].second++;
- v[id].first = x;
- while (id > 0){
- id--; id/=2;
- v[id].first = max(v[id*2+1].first,v[id*2+2].first);
- }
- }
- int get(){
- int x = v[0].first;
- //cout<<x<<"\n";
- int id = gdN - 2 + x;
- v[id].second--;
- if (v[id].second == 0){
- v[id].first = 0;
- while (id > 0){
- id--; id/=2;
- v[id].first = max(v[id*2+1].first,v[id*2+2].first);
- }
- }
- return x;
- }
- };
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int q; cin>>q;
- tree T;
- T.bld();
- for (int i = 0; i < q; ++i){
- int cd; cin>>cd;
- if (cd == 0){
- int k; cin>>k;
- T.ch(k);
- }
- else {
- cout<<T.get()<<"\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement