POJ 2828 Segment Tree Single point update offline engage

Source: Internet
Author: User

Description

Railway tickets were difficult to buy around the Lunar New year in China, so we must get up early and join a long queue ...

The Lunar New year is approaching, but unluckily the Little Cat still had schedules going here and there. Now, he had-to-train-Mianyang, Sichuan Province for the winter camp selection of the national team of Olympia D in Informatics.

It was one o ' clock a.m. and dark outside. Chill Wind from the northwest does not scare off the people in the queue. The cold night gave the Little Cat a shiver. Why isn't find a problem to think?

That is none the less better than freezing to death!

People kept jumping the queue. Since It is too dark around, such moves would not being discovered even by the people adjacent to the queue-jumpers. "If every person in the queue is assigned a integral value and all the information to those who has jumped the queue And where they stand after queue-jumping are given, can I find out the final order of people in the queue? " Thought the Little Cat.

Input

There'll is several test cases in the input. Each test case consists of n + 1 lines where n (1≤ n ≤200,000) was given in the first line of The test case. The nextN lines contain the pairs of values posi and Vali in the increasing order ofI (1≤ iN). For each i, the ranges and meanings ofposi and Vali is as follows:

    • posi ∈[0, i ? 1]-the i-th person came to the queue and stood right behind theposi-T H person in the queue. The booking office was considered, the 0th person, and the person at the front of the queue is considered the first person In the queue.
    • Vali ∈[0, 32767]-the i-th person is assigned the valueVali.

There no blank lines between test cases. Proceed to the end of input.

Output

For each test cases, output a space-separated integers which is the values of people in the order they STA nd in the queue.

Sample Input

40 771 511 332 6940 205231 192431 38900 31492

Sample Output

77 33 69 5131492 20523 3890 19243

Hint

The figure below shows how the Little Cat found out the final order of people in the queue described in the first Test CAs E of the sample input.


Test instructions has n individuals, giving each person the location of each insertion. And the value of this man. Outputs the final value order. Since the team is dynamically changing, it is possible to insert forward from the last insertion. Cc[o] Maintenance node o The corresponding interval can be inserted in the number of people, insert the assumption that the left can be inserted on the left, otherwise inserted on the right, recursive to the leaf node so far ...



/************************************************************************* > File name:f.cpp > Author:acvcla > QQ: > Mail: [email protected] > Created time:2014 October 04 Saturday 22:39 16 seconds *********************** /#include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include <cstring> #include <map> #include <queue> #include <stack> #include <string> #include <cstdlib> #include <ctime> #include <set> #include < Math.h>using namespace Std;typedef long long ll;const int maxn = 2e5 +; #define REP (i,a,b) for (int i= (a); i<= (b); i+ +) #define PB Push_backint cc[maxn<<2],ans[maxn];int loc[maxn],val[maxn];void built (int o,int l,int R) {if (l==r) { Cc[o]=1;return;} int m= (L+R) >>1;built (o<<1,l,m); built (o<<1|1,m+1,r); cc[o]=cc[o<<1]+cc[o<<1|1];} int x,w;void Modify (int o,int l,int r) {cc[o]--;if (l==r) {Ans[l]=w;retuRN;} int m= (L+R) >>1;if (cc[o<<1]>=x) {Modify (o<<1,l,m); return;} x-=cc[o<<1]; Modify (o<<1|1,m+1,r);} int main () {int n;while (~scanf ("%d", &n)) {built (1,1,n); Rep (i,1,n) {scanf ("%d%d", Loc+i,val+i);} for (int i=n;i>=1;i--) {x=loc[i]+1,w=val[i]; Modify (1,1,n);}            printf ("%d", ans[1]); Rep (i,2,n) printf ("%d", ans[i]); printf ("\ n");} return 0;}






POJ 2828 Segment Tree Single point update offline engage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.