Cod sursa(job #2783810)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 15 octombrie 2021 09:24:47
Problema Nums Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

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

class cmp
{
public:
    bool operator()(string a, string b)
    {
        if(a.size() == b.size())
            return a < b;
        return a.size() < b.size();
    }
};
tree < string,  null_type,  cmp,  rb_tree_tag,  tree_order_statistics_node_update > ARB;
map<string, bool > mp;

int main()
{
    int n;
    fin >> n;

    for(int i = 1; i <= n; ++i)
    {
        int t;
        fin >> t;
        if(t == 1)
        {
            string val;
            fin >> val;

            if(mp.find(val) == mp.end())
            {
                ARB.insert(val);
                mp[val] = 1;
            }
        }
        else
        {
            int val;
            fin >> val;
            string rez = *ARB.find_by_order(val - 1);
            fout << rez << '\n';
        }
    }
    return 0;
}