<strong><span style="font-size:18px;"></span></strong><pre name="code" class="cpp">
#include<iostream>
<strong><span style="font-size:18px;">using namespace std;
int n,ans[200005];
struct tt
{
int val;
int pos;
}ll[200005];
struct lll
{
int left;
int right;
int sum;
}node[1000000];
void build(int left,int right,int pos)
{
node[pos].left=left;
node[pos].right=right;
node[pos].sum=right-left+1;
if(left==right)
return;
int mid=(node[pos].left+node[pos].right)/2;
build(left,mid,2*pos);
build(mid+1,right,2*pos+1);
}
void push_up(int pos)
{
node[pos].sum=node[2*pos].sum+node[2*pos+1].sum;
}
int query(int x,int pos)
{
if(node[pos].left==node[pos].right)
return node[pos].left;
if(node[2*pos].sum>=x)
return query(x,2*pos);
else
return query(x-node[2*pos].sum,2*pos+1);
}
void update(int x,int pos)
{
if(node[pos].left==node[pos].right)
{
node[pos].sum--;
return;
}
int mid=(node[pos].left+node[pos].right)/2;
if(x<=mid)
update(x,2*pos);
else
update(x,2*pos+1);
push_up(pos);
}
void solve()
{
int i;
for(i=n;i>=1;i--)
{
int pos=ll[i].pos;
int id=query(pos,1);
ans[id]=ll[i].val;
update(id,1);
}
printf("%d",ans[1]);
for(i=2;i<=n;i++)
printf(" %d",ans[i]);
cout<<endl;
}
int main()
{
while(cin>>n)
{
int i;
for(i=1;i<=n;i++)
{scanf("%d%d",&ll[i].pos,&ll[i].val);
ll[i].pos++;
}
build(1,n,1);
solve();
}
return 0;
}</span></strong>