Pagini recente » Cod sursa (job #1776477) | Istoria paginii utilizator/cont_de_stres_fmmm4rcu | Cod sursa (job #1372021) | Cod sursa (job #204050) | Cod sursa (job #444872)
Cod sursa(job #444872)
#include <cstdio>
#include <algorithm>
#include <ext/hash_map>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
using namespace __gnu_cxx;
#define nmax 100005
#define VIT vector <int> :: iterator
#define pb push_back
string S [nmax];
inline bool cmp (const int &a, const int &b) {
if (S [a].size () > S [b].size ()) return 0;
if (S [a].size () < S [b].size ()) return 1;
if (S [a] > S [b]) return 0;
return 1;
}
int aib [nmax], idx, order [nmax];
string str;
vector <int> opp [nmax];
inline void update (int x) {
for (; x <= idx; x += x & - x) aib [x]++;
}
inline int query (int x) {
int sum = 0;
for (; x >= 1; x -= x & -x) sum += aib [x];
return sum;
}
inline int cbin (int x)
{
int st, dr, mid, ans = 0;
st = 1; dr = idx;
while (st <= dr)
{
mid = (st + dr) / 2;
ans = query (mid);
if (ans < x)
st = mid + 1;
else if (ans > x)
dr = mid - 1;
else if (ans == x)
return mid;
}
return 0;
}
int main ()
{
freopen ("nums.in", "r", stdin);
freopen ("nums.out", "w", stdout);
int m, i, op, qq;
scanf ("%d\n", &m);
for (i = 1; i <= m; i++)
{
scanf ("%d", &op);
if (op == 1)
{
cin >> str;
++idx;
S [idx] = str;
//cout << S [idx] << " ";
}
else if (op == 0)
{
scanf ("%d", &qq);
opp [idx].pb (qq);
}
}
for (i = 1; i <= idx; i++)
order [i] = i;
sort (order + 1, order + idx + 1, cmp);
int a;
for (i = 1; i <= idx; i++)
{
update (order [i]);
if (opp [i].size ())
for (VIT it = opp [i].begin (); it != opp [i].end (); it++)
{
a = cbin (*it);
//printf ("%d\n", a);
cout << S [order [a]] << "\n";
}
}
return 0;
}