POJ 2828 Buy Tickets (line segment tree), poj2828

Source: Internet
Author: User

POJ 2828 Buy Tickets (line segment tree), poj2828

Language:DefaultBuy Tickets
Time Limit:4000 MS   Memory Limit:65536 K
Total Submissions:13847   Accepted:6926

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 was approaching, but unluckily the Little Cat still had schedules going here and there. now, he had to travel by train to Mianyang, Sichuan Province for the winter camp selection of the national team of Olympus in ICS ICs.

It was one o 'clock a.m. and dark outside. chill wind from the northwest did not scare off the people in the queue. the cold night gave the Little Cat a shiver. why not find a problem to think about? That was none the less better than freezing to death!

People kept jumping the queue. since it was too dark around, such moves wocould not be discovered even by the people adjacent to the queue-jumpers. "If every person in the queue is assigned an integral value and all the information about those who have jumped the queue and where they stand after queue-jumping is given, can I find out the final order of people in the queue?" Thought the Little Cat.

Input

There will be several test cases in the input. Each test case consistsN+ 1 lines whereN(1 ≤N≤ 200,000) is given in the first line of the test case. The nextNLines contain the pairs of valuesPosiAndValiIn the increasing orderI(1 ≤IN). For eachI, The ranges and meaningsPosiAndValiAre as follows:

  • Posiε [0,I−1]-I-Th person came to the queue and stood right behindPosi-Th person in the queue. The booking office was considered the 0th person and the person at the front of the queue was considered the first person in the queue.
  • Valiε [0, 32767]-I-Th person was assigned the valueVali.

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

Output

For each test cases, output a single line of space-separated integers which are the values of people in the order they stand 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 case of the sample input.

Source

POJ Monthly -- 2006.05.28, Zhu, Zeyuan

Buy tickets and jump forward from the back to the back, thinking that the back is definitely OK


// Queue, input n, and n Rows a and B indicate that B is inserted in the position of a, and finally output the number of the final team. // pay attention to this question, that is, if the insert position is 0, 1 is required, that is, add 1 # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # define L (x) (x <1) # define R (x) (x <1 | 1) # define MID (x, y) (x + y)> 1) using namespace std; # define N 200005int ans [N], a [N], va [N]; struct stud {int le, ri; int len;} f [N * 4]; int n; void build (int pos, int le, int ri) {f [pos]. le = le; f [pos]. ri = ri; f [pos]. len = ri-le + 1; If (le = ri) return; int mid = MID (le, ri); build (L (pos), le, mid); build (R (pos ), mid + 1, ri);} void update (int pos, int le, int va) {f [pos]. len --; if (f [pos]. le = f [pos]. ri) {ans [f [pos]. le] = va; return;} if (f [L (pos)]. len> = le) update (L (pos), le, va); else update (R (pos), le-f [L (pos)]. len, va);} int main () {int I; while (~ Scanf ("% d", & n) {build (1, 1, n); for (I = 1; I <= n; I ++) scanf ("% d", & a [I], & va [I]); for (I = n; I> = 1; I --) update (1, a [I] + 1, va [I]); for (I = 1; I <= n; I ++) if (I = 1) printf ("% d", ans [I]); else printf ("% d", ans [I]); printf ("\ n");} return 0 ;}





Who has the correspondence between data structure algorithms and POJ questions?

An asterisk indicates a typical question or a better algorithm.

1195 Mobile phones tree Array
1455
1521 Entropy huffman
1703 Find them, Catch them and query the set
1785 Binary Search Heap Construction
1794 Castle Wils Reverse Order
1961 Period KMP recurrence factor
1984 * Navigation Nightmare and check the set + coordinate translation
1986 * Distance Queries LCA
1988 * Cube Stacking and query set applications
1990 * MooFest line segment tree
2010 * Moo University-Financial Aid Max heap-min heap
2182 Lost Cows line segment tree
2183 Bovine Math Geniuses hash
2188 Cow Laundry Reverse Order
2227 The Wedding Juicer heap + floodfill
2236 Wireless Network and query set
2266 * Quadtree Recursion
2269 * Friends expression
2270 Quadtree II or: Florida Jones strikes back will be 2266 vice versa
2299 Ultra-QuickSort Merge Sorting
2352 Stars tree Array
2395 Out of Hay and query set
2482 Stars in Your Window static 2 Cross Tree
2513 Colored Sticks and check the set
2524 Ubiquitous Religions and query set
2528 Mayor's posters line segment tree
2567 Code the Tree
2750 * Potted Flower line segment tree
2777 Count Color line segment tree
2796 Feel Good RMQ
2823 Sliding Window heap or double-end queue
2828 Buy Tickets line segment tree
2886 * Who Gets the Most Candies? Line Segment tree
2892 * Tunnel Warfare tree Array
3214 * Heap post-order traversal. Each node deducts the corresponding sub-guarantee attribute, and then calculates the longest non-descending sequence for the traversal result.
3253 Fence Repair huffman
3263 Tallest Cow line segment tree
3274 * Gold Balanced Lineup hash
3277 City Horizon line segment tree
3320 Jessica's Reading Problem queue operation or minimum heap
3321 * Apple Tree Array
3332 Parsing Real Numbers DFA
3344 Chessboard Dance queue Simulation
3349 Snowflake Snow Snowflakes hash (or brute force)
3437 Tree Grafting dfs Tree construction
3461 Oulipo KMP
3468 A Simple Problem with Integers segment tree Interval Update, lazy operation
3631 Cuckoo Hashing and query Sets
3667 Hotel line segment tree
3690 Constellations trie match
3695 Rectangles matrix cutting... remaining full text>


Related Article

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.