Pagini recente » Cod sursa (job #1486369) | Cod sursa (job #1344031) | Cod sursa (job #2404279) | Cod sursa (job #2960853) | Cod sursa (job #445168)
Cod sursa(job #445168)
#include <cstdio>
#include <algorithm>
#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
#define f first
#define s second
#define mp make_pair
vector <pair <int, string> > S;
struct cmp {
bool operator()(const pair <int, string>& a, const pair <int, string>& b) {
if (a.s.size () == b.s.size ())
return a.s.compare (b.s) < 0;
return a.s.size () < b.s.size ();
}
};
int aib [nmax], idx, order [nmax], i, logN;
string str;
int opp [nmax][3];
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 step, i;
for (step = logN, i = idx; step; step >>= 1)
if (i - step > 0)
if (x <= query (i - step))
i -= step;
return i;
}
int main ()
{
freopen ("nums.in", "r", stdin);
freopen ("nums.out", "w", stdout);
int m,op, qq;
scanf ("%d\n", &m);
for (i = 1; i <= m; i++)
{
scanf ("%d", &op);
if (op == 1)
{
cin >> str;
++idx;
S.pb (mp (idx, str));
opp [i][0] = 1;
//cout << S [idx] << " ";
}
else if (op == 0)
{
cin >> qq;
opp [i][1] = qq;
}
}
for (logN = 1; logN < idx; logN <<= 1);
sort (S.begin (), S.end (), cmp ());
for (i = 0; i < S.size (); i++)
{
//cout << S [i].f << " "<< S [i].s << " "<< i + 1 << endl;
order [S [i].f] = i + 1;
}
int a, j = 0;
for (i = 1; i <= m; i++)
{
if (opp [i][0])
{
if (S [order [j]] != S [order [j + 1]])
update (order [++j]);
}
else
{
a = cbin (opp [i][1]);
printf ("%s\n",S [a - 1].s.c_str ());
}
}
return 0;
}