Pagini recente » Cod sursa (job #2790513) | Cod sursa (job #2415034) | Cod sursa (job #1968189) | Cod sursa (job #3169464) | Cod sursa (job #1418436)
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define x first
#define y second
using namespace std;
const int nmax = 100005;
int n, i, op, cnt, x, flc, lim, aib[nmax];
string s, str[nmax];
unordered_map<string, int> where;
unordered_map<string, bool> viz;
struct cmp
{
bool operator () (const string &a, const string &b) const
{
if (a.size() == b.size())
return a < b;
return a.size() < b.size();
}
};
vector <string> v;
void update(int poz)
{
for (int i = poz; i <= n; i += i & (-i))
aib[i]++;
}
int query(int val)
{
int r = 0;
for (int step = lim; step; step /= 2)
if (r + step < n && aib[r + step] < val)
{
val -= aib[r + step];
r += step;
}
return r + 1;
}
int main()
{
ifstream fin("nums.in");
ofstream fout("nums.out");
fin >> n;
for (i = 1; i <= n; i++)
{
fin >> op;
if (op == 1)
{
fin >> s;
v.pb(s);
}
else
fin >> op;
}
sort(all(v), cmp());
for (auto it : v)
{
cnt++;
where[it] = cnt;
str[cnt] = it;
}
fin.close();
ifstream f("nums.in");
f >> n;
for (lim = 1; 2 * lim <= n; lim *= 2);
for (i = 1; i <= n; i++)
{
f >> op;
if (op == 1)
{
f >> s;
if (viz[s])
continue;
viz[s] = 1;
update(where[s]);
}
else
{
f >> x;
flc = query(x);
fout << str[flc] << '\n';
}
}
return 0;
}