Hdu 2828 Buy Tickets, hdu2828

Source: Internet
Author: User

Hdu 2828 Buy Tickets, hdu2828
Buy TicketsTime Limit: 8000/4000 ms (Java/Other) Memory Limit: 131072/65536 K (Java/Other) Total Submission (s): 31 Accepted Submission (s): 15 Problem 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 <p> There will be several test cases in the input. each test case consists of <I> N </I> + 1 lines where <I> N </I> (1≤< I> N </I> ≤200,000) is given in the first line of the test case. the next <I> N </I> lines contain the pairs of values <I> Pos <sub> I </sub> </I> and <I> Val <sub> I </sub> </I> in the increasing order of <I> I </I> (1 ≤ <I> I </I> ≤ <I> N </ i> ). for each <I> I </I>, the ranges and meanings of <I> Pos <sub> I </sub> </I> and <I> Val <sub> I </sub> </I> are follows: </p> <ul> <li> <I> Pos <sub> I </sub> </I> ε [0, <I> I </I> −1]-The <I> I </I>-th person came to the queue and stood right behind the <I> Pos <sub> I </sub> </I>-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. </li> <I> Val <sub> I </sub> </I> ε [0, 32767]-The <I> I </I>-th person was assigned the value <I> Val <sub> I </sub> </I>. </li> </ul> <p> There no blank lines between test cases. proceed to the end of input. </p>

 

Output <p> 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. </p>

 

Sample Input4 0 77 1 51 1 33 2 69 4 0 20523 1 19243 0 3890

 

Sample Output77 33 69 51 31492 20523 3890

 

SourcePKU is a newbie to the line tree. After it is done, the line tree is just a data structure that can be used. How to Use It should give full play to your imagination .. At the beginning, you still want to use common functions such as lowbit. This question is centered, and the last person inserted in reverse order remains unchanged. Ksum is used at the node to represent the number of vacancies.
#include <iostream>#include <cstdio>#include <algorithm>#include<vector>#include<cstring>using namespace std;int a[200005],b[200005],ans[200005];int tem,t;struct node{    int l,r,ksum;}tr[200005<<2];void build(int n,int l,int r){    tr[n].l=l;    tr[n].r=r;    tr[n].ksum=r-l+1;    if(l==r)        return;    int m=(l+r)>>1;    build(n<<1,l,m);    build(n<<1|1,m+1,r);}void f(int k,int v,int n){    int m=(tr[n].l+tr[n].r)>>1;    if(tr[n].l==tr[n].r)    {        tr[n].ksum=0;        ans[tr[n].l]=v;        return;    }    if(tr[n<<1].ksum>=k)        f(k,v,n<<1);    else        f(k-tr[n<<1].ksum,v,n<<1|1);    tr[n].ksum=tr[n<<1].ksum+tr[n<<1|1].ksum;}int main(){    while(~scanf("%d",&t))    {        build(1,1,t);        tem=0;        for(int i=1;i<=t;i++)            scanf("%d%d",&a[i],&b[i]);        for(int i=t;i>0;i--)            f(a[i]+1,b[i],1);        for(int i=1;i<t;i++)            cout<<ans[i]<<" ";            cout<<ans[t]<<endl;    }}

  

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.