Pagini recente » Cod sursa (job #1724368) | Cod sursa (job #1414822) | Cod sursa (job #159941) | Cod sursa (job #658727) | Cod sursa (job #1317456)
#include <iostream>
#include <set>
#include <string>
#include <algorithm>
using namespace std;
const int VALUE = 33000;
const int NR = 700;
const int NMAX = 100002;
set < string >S[NMAX];
int cnt[VALUE][10];
int aib[NMAX];
inline void Update(int pos)
{
for(;pos<NMAX;pos+=pos&-pos)
aib[pos]++;
}
inline int Query(int pos)
{
int ret = 0;
for(;pos>0;pos-=pos&-pos)
ret += aib[pos];
return ret;
}
int main()
{
freopen("nums.in","r",stdin);
freopen("nums.out","w",stdout);
cin.sync_with_stdio(false);
string s;
int pos, n;char ch;
cin >> n;
while(n--)
{
cin >> ch;
if(ch=='1'){
cin >> s;
int L = s.length();
if(S[L].find(s)!=S[L].end())
continue;
Update(L);
S[L].insert(s);
}
else{
cin >> pos;
int L = NMAX;
int Left = 1;
int Right = L-1,mid;
while(Left<=Right)
{
mid = (Left+Right)/2;
if(Query(mid) >= pos)
{
L = mid;
Right=mid-1;
}
else
Left = mid+1;
}
pos -= Query(L-1);
//if(L >= VALUE || pos <= NR)
{
auto x = S[L].begin();
for(int i=1;i<pos;++i,x++);
cout<<*x<<"\n";
}
}
}
return 0;
}