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 ...
随机推荐
- 数据结构之C语言模拟整数数组实现
#include <stdio.h> #include <malloc.h> #include <stdlib.h> typedef struct Arr { in ...
- Spring Boot2中Spring Security导致Eureka注册失败
将Spring Boot升级到2.0,Spring Cloud升级到Finchley.M8时,Eureka注册就报错了 Eureka Server配置: server.port=9011 spring ...
- 【Android 界面效果47】RecyclerView详解
RecylerView作为 support-library发布出来,这对开发者来说绝对是个好消息.因为可以在更低的Android版本上使用这个新视图.下面我们看如何获取 RecylerView.首先打 ...
- linux基础命令-mkdir/tree/rmdir
命令行的展开 ~: 展开为用户的主目录 ~USERNAME: 展开为指定用户的主目录 {}:可承载一个以逗号分隔的列表,并将其展开为多个路径 [root@host01 tmp]# mkdir -vp ...
- 【js基础修炼之路】--创建文档碎片document.createDocumentFragment()
讲这个方法之前,我们应该先了解下插入节点时浏览器会做什么. 在浏览器中,我们一旦把节点添加到document.body(或者其他节点)中,页面就会更新并反映出这个变化,对于 ...
- golang实现文件上传权限验证(超简单)
Go语言创建web server非常简单,部署也很容易,不像IIS.Apache等那么重量级,需要各种依赖.配置.一些功能单一的web 服务,用Go语言开发特别适合.http文件上传下载服务,在很多地 ...
- IOS 九宫格算法
@interface ViewController () @property (nonatomic,strong) NSArray *apps; //获取.plist数据 @end @implemen ...
- VUE在页面没加载完的时候会显示原代码的处理方法
CSS: [v-cloak] { display: none; } HTML : <div v-cloak> {{ message }} </div> 其中 v-cloak官方 ...
- eplise中运行提示 A fatal error has been detected by the java runtime environment
今天一同事出现运行项目时,提示 A fatal error has been detected by the java runtime environment,具体表现是使用我们框架,不能正常的打印日 ...
- Uva 10375 选择与除法 唯一分解定理
题目链接:https://vjudge.net/contest/156903#problem/E 题意:已知 求:C(p,q)/C(r,s) 其中p,q,r,s都是10^4,硬算是肯定超数据类型的. ...