The Nima line segment tree has finally made some progress and is decisive. I have never known what to record with the line segment tree in specific problems. It seems that there are too few questions I have done, I have seen very few types. I have to work hard in the future. This time I have to finish the line tree album at home .... Weak.
At the beginning of this question, I did not know what the line segment tree recorded, how to use the line segment tree to express it, or how to do it. I later read the report of other people's problem solving and understood it for a long time, only then can we understand that we have to work hard and think more;
Because this question is a matter of queuing, the final result will be known only after all the information is entered. The line segment tree is used to indicate the number of gaps in the recorded range, and then the last one is inserted;
#include<cstdio>#include<algorithm>#include<cmath>#include<string.h>using namespace std;#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1 | 1const int N=200002;int num[N<<2];int res[N<<2];void PushUp(int rt){ num[rt]=num[rt<<1]+num[rt<<1 | 1];}void build(int l,int r,int rt){ res[rt]=0; if(l==r){num[rt]=1;return;} int mid=(l+r)>>1; build(lson); build(rson); PushUp(rt);}void update(int p,int val,int l,int r,int rt){ if(l==r) {num[rt]--; res[l]=val;return; } int mid=(l+r)>>1; if(num[rt<<1]>=p)update(p,val,lson); else update(p-num[rt<<1],val,rson); PushUp(rt);}pair<int,int>a[N];int main(){ int n,i,val; while(~scanf("%d",&n)) { build(1,n,1); for(int i=0;i<n;i++) { scanf("%d%d",&a[i].first,&a[i].second); } for(int i=n-1;i>=0;i--) { update(a[i].first+1,a[i].second,1,n,1); } printf("%d",res[1]); for(int i=2;i<=n;i++) { printf(" %d",res[i]);} printf("\n"); } return 0;}