Pagini recente » Cod sursa (job #3277800) | Cod sursa (job #2725593) | Cod sursa (job #2776527) | Cod sursa (job #2850666) | Cod sursa (job #652634)
Cod sursa(job #652634)
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#define NMAX 100005
#define LMAX (1<<18)
#define pb push_back
#define pii pair <int,int>
#define mp make_pair
#define f first
#define s second
using namespace std;
int t,op,ord[NMAX],C[NMAX],D[LMAX],r,poz,val[NMAX],F[NMAX],L[LMAX],R[LMAX],M[LMAX];
char line[NMAX],ap[NMAX];
vector <char> A[NMAX];
pii B[NMAX];
bool comp(int x,int y)
{
if (A[x].size()<A[y].size())
return 1;
if (A[x].size()>A[y].size())
return 0;
int i;
for (i=0; i<A[x].size(); i++)
{
if (A[x][i]<A[y][i])
return 1;
if (A[x][i]>A[y][i])
return 0;
}
return 1;
}
inline int egal(int x,int y)
{
if (A[x].size()!=A[y].size())
return 0;
int i;
for (i=0; i<A[x].size(); i++)
if (A[x][i]!=A[y][i])
return 0;
return 1;
}
void update()
{
poz=F[poz];
for ( ; poz; poz>>=1)
D[poz]++;
}
void cauta(int st,int dr,int nod)
{
if (st==dr)
{
int i;
for (i=0; i<A[val[st]].size(); i++)
printf("%c",A[val[st]][i]);
printf("\n");
return ;
}
int mij=M[nod];
if (D[L[nod]]<poz)
{
poz-=D[L[nod]];
cauta(mij+1,dr,R[nod]);
}
else
cauta(st,mij,L[nod]);
}
inline int cif(char x)
{
return x>='0' && x<='9';
}
void cstr(int st,int dr,int nod)
{
if (st==dr)
{
F[st]=nod;
return ;
}
int mij=(st+dr)>>1;
M[nod]=mij; L[nod]=nod<<1; R[nod]=L[nod]+1;
cstr(st,mij,L[nod]);
cstr(mij+1,dr,R[nod]);
}
int main()
{
freopen("nums.in","r",stdin);
freopen("nums.out","w",stdout);
scanf("%d\n",&t);
int i,tip;
for (i=1; i<=t; i++)
{
scanf("%d",&tip);
if (tip==1)
{
fgets(line+1,NMAX,stdin);
poz=0; op++;
while (!cif(line[poz+1])) poz++;
while (cif(line[poz+1])){ poz++; A[op].pb(line[poz]);}
ord[op]=op;
B[i]=mp(tip,op);
}
else
{
scanf("%d",&poz);
B[i]=mp(tip,poz);
}
}
sort(ord+1,ord+op+1,comp);
return 0;
}