hdu 2828 Buy Tickets
2018-06-17 21:49:30来源:未知 阅读 ()
Buy Tickets
Time Limit : 8000/4000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 31 Accepted Submission(s) : 15
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 Olympiad in Informatics.
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 would 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.
#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; } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash