此题跟poj 2182基本一样,请看我的2182的那篇博客讲的很清楚
代码改动在20个字符左右........
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <string.h>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <map>
#include <limits>
#define LL long long
#define Vi vector<int>
#define Si set<int>
#define readf freopen("input.txt","r",stdin)
#define writef freopen("output.txt","w",stdout)
#define FF(i,a) for(int i(0); i < (a); i++)
#define FD(i,a) for(int i(a); i >= (1); i--)
#define FOR(i,a,b) for(int i(a);i <= (b); i++)
#define FOD(i,a,b) for(int i(a);i >= (b); i--)
#define PD(a) printf("%d",a)
#define SET(a,b) memset(a,b,sizeof(a))
#define SD(a) scanf("%d",&(a))
#define LN printf("\n")
#define PS printf(" ")
#define pb push_back
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const double pi = acos(-1.0);
const int maxn = 200001;
const int INF = 99999999;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
using namespace std;
int a[maxn],b[maxn],ans[maxn];
int len[maxn<<2];
void PushUP(int rt){
len[rt]=len[rt<<1]+len[rt<<1|1];
}
void build(int l,int r,int rt){
if(l==r){
len[rt]=1;
return ;
}
int m=(l+r)>>1;
build(lson);
build(rson);
PushUP(rt);
}
int query(int l,int r,int rt,int x){
if(l==r){
len[rt]=0;
return r;
}
int m=(l+r)>>1;
int ret;
if(x<=len[rt<<1]) ret=query(lson,x);
else ret=query(rson,x-len[rt<<1]);
PushUP(rt);
return ret;
}
void print(int l,int r,int rt){
printf("l:%d r:%d len:%d \n",l,r,len[rt]);
if(l==r)
return ;
int m=(l+r)>>1;
print(lson);
print(rson);
}
int main()
{
int N;
while(~SD(N)&&N){
build(1,N,1);
FOR(i,1,N) scanf("%d%d",&a[i],&b[i]);
FOD(i,N,1){
int k=query(1,N,1,a[i]+1);
ans[k]=b[i];
}
printf("%d",ans[1]);
FOR(i,2,N)
printf(" %d",ans[i]);
LN;
}
return 0;
}