Pagini recente » Cod sursa (job #2672002) | Cod sursa (job #951851) | Cod sursa (job #3207949) | Cod sursa (job #924897) | Cod sursa (job #2648271)
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, pii> muchie;
const ll NMAX = 120005;
const ll INF = (1 << 22) - 1;
const ll MOD = 1000000007;
const ll BLOCK = 101;
class FenwickTree{
int aib[NMAX];
public:
void update(int x){
for(int i = x;i < NMAX;i+=i&(-i)){
aib[i] += 1;
}
}
int query(int x){
int s = 0;
for(int i = x;i > 0;i-=i&(-i))
s += aib[i];
return s;
}
int kth(int k){
int r = 0, pas = 1 << 16;
while(pas){
if(query(r + pas) <= k)
r += pas;
pas /= 2;
}
return r;
}
}aib;
unordered_map <string,int> mp;
string coresp[NMAX];
unordered_map <string,bool> mm;
string v[NMAX];
int vf = 0;
bool cmp(string a, string b) {
if(b.size() > a.size()) {
return 1;
}
if(a.size() > b.size()) {
return 0;
}
for(int i = 0; i < a.size(); i++) {
if(a[i] != b[i])
return (a[i] < b[i]);
}
}
struct query{
int x;
string y;
int a;
}qq[NMAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ifstream cin("nums.in");
ofstream cout("nums.out");
int n,i;
cin >> n;
for(i = 1; i <= n; i++) {
cin >> qq[i].x;
if(qq[i].x == 1){
cin >> qq[i].y;
v[++vf] = qq[i].y;
}else{
cin >> qq[i].a;
}
}
sort(v + 1,v + vf + 1,cmp);
for(i = 1; i <= n; i++) {
if(v[i] != v[i - 1]){
mp[v[i]] = i;
coresp[i] = v[i];
}
}
for(i = 1; i <= n; i++) {
int x = qq[i].x;
if(x == 0) {
int y;
y = qq[i].a;
cout << coresp[aib.kth(y)] << "\n";
} else {
string s;
s = qq[i].y;
if(mm[s]){
continue;
}
mm[s] = 1;
aib.update(mp[s]);
}
}
return 0;
}