Pagini recente » Cod sursa (job #1461521) | Cod sursa (job #72435) | Istoria paginii runda/nustiucesazic/clasament | Cod sursa (job #1498235) | Cod sursa (job #884936)
Cod sursa(job #884936)
#include <algorithm>
#include <fstream>
#include <string>
using namespace std;
ifstream fin("nums.in");
ofstream fout("nums.out");
const int nmax= 100000;
const int n2max= 131072;// n2max= smallest x such as x>=nmax and x==1<<y, y positive integer
int qt[nmax+1];
string s[nmax+1];
int v[nmax+1], p[nmax+1];
struct hi_cmp{
bool operator()(int x, int y){
if (s[x].size()!=s[y].size()){
return s[x].size()<s[y].size();
}else{
return s[x]<s[y];
}
}
};
int t[2*n2max];
void it_upd(int x){
if (t[x]==0){
for (int i= x; i>0; i/= 2){
++t[i];
}
}
}
int it_que(int node, int nl, int nr, int x){
if (nl==nr){
return nl;
}else if (x<=t[2*node]){
return it_que(2*node, nl, (nl+nr)/2, x);
}else{
return it_que(2*node+1, (nl+nr)/2+1, nr, x-t[2*node]);
}
}
int main(){
int nq;
fin>>nq;
int n= 0;
for (int cq= 1; cq<=nq; ++cq){
fin>>qt[cq];
fin>>s[cq];
if (qt[cq]==1){
++n;
v[n]= cq;
}
}
sort(v+1, v+n+1, hi_cmp());
int n2= 1; p[v[1]]= 1;
for (int i= 2; i<=n; ++i){
if (s[v[i]]!=s[n2]){
++n2;
}
p[v[i]]= n2;
}
for (int i= 1; i<=nq; ++i){
v[p[i]]= i;
}
for (n2= 1; n2<n; n2*= 2){
}
for (int cq= 1; cq<=nq; ++cq){
if (qt[cq]==0){
int x= 0;
for (int i= 0; i<(int)s[cq].size(); ++i){
x= x*10+s[cq][i]-'0';
}
int aux= v[it_que(1, 1, n2, x)];
fout<<s[aux]<<"\n";
}else{
it_upd(p[cq]+n2-1);
}
}
return 0;
}