Buy tickets
Time limit:4000 Ms |
|
Memory limit:65536 K |
Total submissions:12296 |
|
Accepted:6071 |
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 ≤I≤N). 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
For the same code, the running time of different compilers is a multiple ..
Run ID |
User |
Problem |
Result |
Memory |
Time |
Language |
Code Length |
Submit time |
13039660 |
Changmu |
2828 |
Accepted |
4536 K |
1375 Ms |
C ++ |
953b |
00:09:31 |
13039659 |
Changmu |
2828 |
Accepted |
4764 K |
3391 Ms |
G ++ |
953b |
00:08:47 |
This question has been around for a long time. The line segment Tree node stores the number of free line segments in the interval. Because the interval is right-open, it can also be seen as the number of idle lines at the left endpoint, the update function determines the insertion interval and updates the number of idle elements (that is, the value of a line segment Tree node). The most important thing is that the number of idle elements needs to be inserted in reverse order after reading the node, for example, reading POs in reverse order, after Val, it indicates that there is a pos space in front of the position to be inserted at this point. After the logic is cleared, the coding will take place ~~
# Include <stdio. h ># define maxn 200002 # define lson L, mid, RT <1 # define rson mid, R, RT <1 | 1 struct node {int POs, Val ;} arr [maxn]; int tree [maxn <2], ANS [maxn]; void build (int l, int R, int RT) {tree [RT] = R-l; If (tree [RT] = 1) return; int mid = (L + r)> 1; build (lson ); build (rson);} void Update (INT POs, int Val, int L, int R, int RT) {-- tree [RT]; If (R-l = 1) {ans [l] = val; return;} int mid = (L + R)> 1; if (tree [RT <1]> POS) Update (Pos, Val, lson ); else Update (POS-tree [RT <1], Val, rson);} int main () {int N, POs, Val, I; while (scanf ("% d", & n) = 1) {for (I = 0; I <n; ++ I) scanf ("% d ", & amp; arr [I]. POs, & arr [I]. val); Build (0, N, 1); // pay attention to the right endpoint. The line segment tree stores the line segment information for (I = n-1; I> = 0; -- I) Update (ARR [I]. POs, arr [I]. val, 0, N, 1); for (I = 0; I <n; ++ I) printf ("% d % C", ANS [I], I! = (N-1 )? '': '\ N');} return 0 ;}