hdu 2828 Buy Tickets
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;
}
}
hdu 2828 Buy Tickets的更多相关文章
- hdu 2828 Buy Tickets(线段树)
一道不算复杂的线段树,就是数据处理需要好好想一下. 将输入的所有数据从后往前输入,对于最后一个值,如果它想插入第i个位置,那么他就必须在前面留下i-1个位置.对于倒数第二个人,如果他想插入j位置,那么 ...
- poj 2828 Buy Tickets (线段树(排队插入后输出序列))
http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissio ...
- POJ 2828 Buy Tickets(排队问题,线段树应用)
POJ 2828 Buy Tickets(排队问题,线段树应用) ACM 题目地址:POJ 2828 Buy Tickets 题意: 排队买票时候插队. 给出一些数对,分别代表某个人的想要插入的位 ...
- poj 2828 Buy Tickets(树状数组 | 线段树)
题目链接:poj 2828 Buy Tickets 题目大意:给定N,表示有个人,给定每一个人站入的位置,以及这个人的权值,如今按队列的顺序输出每一个人的权值. 解题思路:第K大元素,非常巧妙,将人入 ...
- poj 2828 Buy Tickets 【线段树点更新】
题目:id=2828" target="_blank">poj 2828 Buy Tickets 题意:有n个人排队,每一个人有一个价值和要插的位置,然后当要插的位 ...
- 线段树(单点更新) POJ 2828 Buy tickets
题目传送门 /* 结点存储下面有几个空位 每次从根结点往下找找到该插入的位置, 同时更新每个节点的值 */ #include <cstdio> #define lson l, m, rt ...
- poj 2828 buy Tickets 用线段树模拟带插入的队列
Buy Tickets Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2 ...
- POJ 2828 Buy Tickets(线段树 树状数组/单点更新)
题目链接: 传送门 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Description Railway tickets were d ...
- poj 2828 Buy Tickets【线段树单点更新】【逆序输入】
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 16273 Accepted: 8098 Desc ...
随机推荐
- React.js 小书 Lesson2 - 前端组件化(一):从一个简单的例子讲起
作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson2 转载请注明出处,保留原文链接和作者信息. 很多课程一上来就给大家如何配置环境.怎么写 Re ...
- 【linux】关于linux命令
1. 删除空目录文件夹rmdir [options] DIRECTORY Ubuntu默认的源是国外的,下载速度会比较慢,cd /etc/apt gedit /etc/apt/
- vue学习中遇到的onchange、push、splice、forEach方法使用
最近在做vue的练习,发现有些js中的基础知识掌握的不牢,记录一下: 1.onchange事件:是在域的内容改变时发生,单选框与复选框改变后触发的事件. 2.push方法:向数组的末尾添加一个或多个元 ...
- ASP.NET操作DataTable各种方法
转:http://www.cnblogs.com/isking/p/6178268.html http://www.cnblogs.com/sntetwt/p/3496477.html public ...
- Javascript 学习 Boolean
构造函数 new Boolean(value) //构造函数 Boolean(value) //转换函数 参数 value 由布尔对象存放的值或者要转换成布尔值的值 返回值 当作为一个构造函数(带有运 ...
- iOS 时间戳和时间互换,计算两日期相隔天数
/* *获取当前系统时间的时间戳 */ +(NSInteger)getNowTimestamp; /** * 获取当前时间 */ + (NSString *)getNowTimeTampF ...
- Spring自定义注解配置切面实现日志记录
一: spring-mvc.xml: <!--配置日志切面 start,必须与mvc配置在同一个配置文件,否则无法切入Controller层--><!-- 声明自动为spring容器 ...
- Hibernate课程 初探多对多映射2-1 创建数据库表
--创建表 -- 创建项目表 create table project( proid int(10) not null comment '项目Id', proname varchar(30) co ...
- 设置Tomcat的字符编码
在 server.xml 中的 Connector 标签在加入 URIEncoding="UTF-8" 属性. <Connector port="8080" ...
- jQueryMobile(一)
一].jQuery Mobile 页面 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta ...