Pagini recente » Cod sursa (job #945232) | Cod sursa (job #109815) | Cod sursa (job #2711943) | Cod sursa (job #2284498) | Cod sursa (job #612966)
Cod sursa(job #612966)
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
char ch[100002];
int a[262143];
struct str{int x;vector <long long> v;} c[100001],v[100001];
bool cmp_str(str x,str y)
{
if (x.v.size()!=y.v.size())
return x.v.size()<y.v.size();
for (unsigned int i=0;i<x.v.size();++i)
if (x.v[i]!=y.v[i])
return x.v[i]<y.v[i];
return 1;
}
int main()
{
int n,m=0,i,j,k,l,aux,aux2,x,step;
freopen("nums.in","r",stdin);
freopen("nums.out","w",stdout);
scanf("%d\n",&n);
for (i=1;i<=n;++i)
{
fgets(ch,sizeof(ch),stdin);
l=strlen(ch)-1;
if (i==n&&ch[l]>='0'&&ch[l]<='9')
++l;
c[i].x=ch[0]-'0';
aux2=(l-2)/19;
if ((l-2)%19)
++aux2;
c[i].v.resize(aux2);
v[i].v.resize(aux2);
for (j=l-1;j>1;j-=19)
{
for (aux=0,k=j-19;k<=j;++k)
if (k>1)
aux=aux*10+ch[k]-'0';
--aux2;
c[i].v[aux2]=aux;
if (ch[0]=='1')
{
++m;
v[m].v[aux2]=aux;
}
}
}
sort(v+1,v+m+1,cmp_str);
for (x=1;x<m;x<<=1);
for (--x,i=1;i<=n;++i)
if (c[i].x)
{
for (step=x+1,j=1;step;step>>=1)
if (j+step<=m&&cmp_str(v[j+step],c[i]))
j+=step;
if (!a[x+j])
{
j=x+j;
while (j)
{
++a[j];
j/=2;
}
}
}
else
{
aux=c[i].v[0];
for (j=1;j<=x;)
if (a[j*2]<=aux)
{
aux-=a[j*2];
j=j*2+1;
}
else
j*=2;
--j;
for (k=0;k<v[j-x].v.size();++k)
printf("%lld",v[j-x].v[k]);
printf("\n");
}
return 0;
}