Pagini recente » Cod sursa (job #946495) | Cod sursa (job #1586531) | Cod sursa (job #1951130) | Cod sursa (job #1404546) | Cod sursa (job #1539187)
/**
* Code by Patrick Sava
* "Spiru Haret" National College of Bucharest
**/
# include "fstream"
# include "cstring"
# include "vector"
# include "queue"
# include "bitset"
# include "algorithm"
# include "map"
# include "set"
# include "unordered_map"
# include "deque"
# include "string"
# include "iomanip"
# include "cmath"
# include "stack"
# include "cassert"
const char IN [ ] = "nums.in" ;
const char OUT [ ] = "nums.out" ;
using namespace std ;
# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( register int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( register int a = b ; a >= c ; -- a )
const int MAX = 1e5 + 14 ;
ifstream cin ( IN ) ;
ofstream cout ( OUT ) ;
unordered_map < string , int > H ;
unordered_map < string , int > X ;
string v [ MAX ] ;
int cate ;
vector < pair < int , string > > Q ;
string inv [ MAX ] ;
int arb [ MAX * 4 ] ;
inline void baga ( int nod , int st , int dr , int pos )
{
if ( st == dr ) {
arb [ nod ] ++ ;
return ;
}
int mij = ( st + dr ) >> 1 ;
if ( pos <= mij )
baga ( nod << 1 , st , mij , pos ) ;
else baga ( nod << 1 | 1 , mij + 1 , dr , pos ) ;
arb [ nod ] = arb [ nod << 1 ] + arb [ nod << 1 | 1 ] ;
}
int caut ( int nod , int st , int dr , int k )
{
if ( st == dr )
return st ;
int mij = ( st + dr ) >> 1 ;
if ( arb [ nod << 1 ] >= k )
return caut ( nod << 1 , st , mij , k ) ;
else return caut ( nod << 1 | 1 , mij + 1 , dr , k - arb [ nod << 1 ] ) ;
}
inline bool cmp ( string a , string b )
{
if ( a.length ( ) > b.length ( ) ) return 0 ;
else if ( a.length ( ) < b.length ( ) ) return 1 ;
return a.compare ( b ) < 0 ;
}
int main()
{
int n ;
cin >> n ;
while ( n -- )
{
int a ;
cin >> a ;
if ( a == 1 ){
string b ;
cin >> b ;
Q.push_back( { a , b } ) ;
if ( H [ b ] == 0 ) {
H [ b ] = 1 ;
++ cate ;
v [ cate ] = b ;
}
}
else {
int b ;
cin >> b ;
Q.push_back ( { -b , "muie" } ) ;
}
}
sort ( v + 1 , v + cate + 1 , cmp ) ;
int e = 0 ;
FORN ( i , 1 , cate ) {
H [ v [ i ] ] = ++ e ;
inv [ e ] = v [ i ] ;
}
//for ( int i = 1 ; i <= e ; ++ i )
// cout << inv [ i ] << '\n' ;
//cout << endl << endl ;
for ( auto x : Q ){
if ( x.first == 1 ){
if ( X [ x.second ] ) continue ;
X [ x.second ] = 1 ;
int pos = H [ x.second ] ;
baga ( 1 , 1 , e , pos ) ;
}
else if ( x.first <= 0 ) {
cout << inv [ caut ( 1 , 1 , e , -x.first ) ] << '\n' ;
}
}
return 0;
}