Pagini recente » Cod sursa (job #1961434) | Cod sursa (job #1336107) | Cod sursa (job #423073) | Cod sursa (job #2378906) | Cod sursa (job #632429)
Cod sursa(job #632429)
# include <algorithm>
# include <fstream>
# include <cstring>
# include <string>
# include <vector>
using namespace std;
const char *FIN = "nums.in", *FOU = "nums.out";
const int MAX = 100005;
vector < int > ind[MAX];
vector < string > sir;
vector < pair <int, string> > T;
string S;
int N, cnt, max_len, poz[MAX], dp[MAX], ai[MAX << 2];
inline bool comp (const int x, const int y) {
return sir[x].compare (sir[y]) < 0;
}
void update (int nod, int val) {
for (; nod <= cnt; ai[nod] += val, nod += nod & -nod);
}
int query (int nod) {
int sol;
for (sol = 0; nod > 0; sol += ai[nod], nod -= nod & -nod);
return sol;
}
/*void update (int nod, int st, int dr, int poz) {
if (st == dr) {
ai[nod] = 1;
return ;
}
int mij = (st + dr) >> 1;
if (poz <= mij) update (nod << 1, st, mij, poz);
else update (nod << 1 | 1, mij + 1, dr, poz);
ai[nod] = ai[nod << 1] + ai[nod << 1 | 1];
}
int query (int nod, int st, int dr, int poz) {
if (st == dr) return dr;
int mij = (st + dr) >> 1;
return poz <= ai[nod << 1] ? query (nod << 1, st, mij, poz) : query (nod << 1 | 1, mij + 1, dr, poz - ai[nod << 1]);
}*/
int main (void) {
ifstream f (FIN);
ofstream g (FOU);
f >> N;
for (int i = 1, ce, lun; i <= N; ++i) {
f >> ce >> S, T.push_back (make_pair (ce, S));
if (ce) {
max_len = max (max_len, lun = S.size ());
sir.push_back (S), ind[lun].push_back (sir.end () - sir.begin () - 1);
}
}
for (int i = 0, aux; i <= max_len; ++i)
if (ind[i].size ()) {
sort (ind[i].begin (), ind[i].end (), comp);
dp[poz[aux = ind[i].front ()] = ++cnt] = aux;
for (vector <int> :: iterator it = ind[i].begin () + 1; it != ind[i].end (); ++it) {
poz[*it] = sir[aux].compare (sir[*it]) ? ++cnt : cnt;
aux = dp[cnt] = *it;
}
}
int pp = 0;
for (vector < pair <int, string> > :: iterator it = T.begin (); it != T.end (); ++it) {
if (it -> first == 1)
update (poz[pp++], 1);
else {
int k = 0;
for (string :: iterator IT = it -> second.begin (); IT != it -> second.end (); ++IT)
k = k * 10 + *IT - '0';
g << sir[dp[query (k - 1)] + 1] << "\n";
}
}
}