Pagini recente » Cod sursa (job #3171719) | Cod sursa (job #1471644) | Cod sursa (job #1021753) | Cod sursa (job #263709) | Cod sursa (job #1094544)
#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int NMAX = 100010;
int N, T, Ind[NMAX], Aib[NMAX];
bool Used[NMAX];
struct Query
{
int Type, Pos;
string S;
}Q[NMAX];
struct Comp
{
bool operator() (const int &i, const int &j) const
{
if(Q[i].S.length() != Q[j].S.length()) return Q[i].S.length() < Q[j].S.length();
return Q[i].S < Q[j].S;
}
};
int LSB(int X)
{
return (X & (X - 1)) ^ X;
}
void Update(int Pos)
{
for(; Pos <= N; Pos += LSB(Pos))
Aib[Pos] ++;
}
int Find(int K)
{
int Pos = 0, Cnt = 0, Step;
for(Step = (1 << 20); Step; Step >>= 1)
if(Pos + Step <= N && Cnt + Aib[Pos + Step] < K)
Cnt += Aib[Pos + Step], Pos += Step;
return Pos + 1;
}
int main()
{
ifstream fin("nums.in");
ofstream fout("nums.out");
fin >> T;
for(int i = 1; i <= T; ++ i)
{
fin >> Q[i].Type;
if(Q[i].Type == 0) fin >> Q[i].Pos;
else
{
fin >> Q[i].S;
Ind[ ++ N] = i;
}
}
sort(Ind + 1, Ind + N + 1, Comp());
for(int i = 1; i <= N; ++ i)
if(Q[ Ind[i] ].S == Q[ Ind[i - 1] ].S)
Q[ Ind[i] ].Pos = Q[ Ind[i - 1] ].Pos;
else
Q[ Ind[i] ].Pos = i;
for(int i = 1; i <= T; ++ i)
if(Q[i].Type == 0)
fout << Q[ Ind[Find(Q[i].Pos)] ].S << "\n";
else if(!Used[ Q[i].Pos ])
Used[ Q[i].Pos ] = 1, Update(Q[i].Pos);
}