Cod sursa(job #1878774)

Utilizator StarGold2Emanuel Nrx StarGold2 Data 14 februarie 2017 14:15:48
Problema Nums Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
/*
    Pur si simplu: GENIAL
    Inspirat dupa: http://www.infoarena.ro/job_detail/1837619?action=view-source
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

fstream in ( "nums.in" , ios::in  );
fstream out( "nums.out", ios::out );

template <class key_type>
using super_tree = tree<key_type, null_type,
    less<key_type>, rb_tree_tag, tree_order_statistics_node_update>;

string str;
super_tree< pair<int, string> > mst;

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

    int n;
    in >> n;

    for( int i = 1; i <= n; i ++ ) {
        int x, k;
        in >> x;

        switch( x ) {
            case 1:
                in >> str;
                mst.insert( make_pair( str.length(), str ) );
                break;
            case 0:
                in >> k;
                out << ( *mst.find_by_order( k - 1 ) ).second << "\n";
                break;
        }
    }

    return 0;
}