2828Buy ticket

2024-09-02 11:58
文章标签 ticket 2828buy

本文主要是介绍2828Buy ticket,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

算是自己写的线段树吧,当然也参考了别人的代码,一次ac,小小的成就感
Buy Tickets
Time Limit: 4000MSMemory Limit: 65536K
Total Submissions: 11957Accepted: 5886

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 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.

Input

There will be several test cases in the input. Each test case consists of N + 1 lines where N (1 ≤ N ≤ 200,000) is given in the first line of the test case. The next N lines contain the pairs of values Posi and Vali in the increasing order of i (1 ≤ i ≤ N). For each i, the ranges and meanings of Posi and Vali are as follows:

  • Posi ∈ [0, i ? 1] — The i-th person came to the queue and stood right behind the Posi-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] — The i-th person was assigned the value Vali.

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

4
0 77
1 51
1 33
2 69
4
0 20523
1 19243
1 3890
0 31492

Sample Output

77 33 69 51
31492 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.

2828Buy ticket - JIM - 叶沁寒

Source

POJ Monthly--2006.05.28, Zhu, Zeyuan


#include<stdio.h>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int maxn=200000;
int i,re[maxn<<2];
struct node
{
int l;
int r;
int d;                          // d 表示 l 到 r 区间剩余的可加入的空白处
}max[maxn<<2];
struct lnode
{
int pos;                           
int val;
}ti[maxn<<2];                       //该数组用于存放输入的数据
void pushup(int rt)
{
max[rt].d=max[rt<<1].d+max[rt<<1|1].d;
}
void build(int l,int r,int rt)
{
max[rt].l=l;                       //把线段树存于数组里面,后面的更新update()直接更新数组
max[rt].r=r;
max[rt].d=r-l+1;
if(l==r)
return;
int m=(l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
void update(int w,int p)               
{
if(max[w].l==max[w].r)
{
re[max[w].l]=ti[i].val;                         // re[ ]数组用于存放输出的数
max[w].d--;                                       
return;
}
if(max[w<<1].d>=p)                         //此处可模拟一下,左边有位置让ti[i].val,  那么pos的值不用改变
update(w <<1,p);
else                                                   //否则,用pos值减去左子树的d值即max[w<<1].d,那么可以得到pos在右边的值
update(w <<1|1,p-max[w<<1].d);
pushup(w);
}
int main()
{
int t;
while(scanf("%d",&t)!=EOF)
{
build(1,t,1);
for(i=1;i<=t;i++)
scanf("%d%d",&ti[i].pos,&ti[i].val);             
for(i=t;i>0;i--)                        //倒序输入更新线段树刚好符合题目条件,自己试一下是那样的
update(1,ti[i].pos+1);
  for(i=1;i<t;i++)
  printf("%d ",re[i]);
  printf("%d\n",re[t]);
}
return 0;
}

这篇关于2828Buy ticket的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1129890

相关文章

IDEA 2019的Cannot obtain ticket--Connection timed out: connect

IDEA用了一年多后出现需要注册的情况,版本:2019.3.3 U版 参考如下博客解决: Cannot obtain ticket from http://fls.jetbrains-agent.com due to connectivity problem:Connection time-CSDN博客

抖音bd-ticket-guard-ree-public-key

上次的文章里说到bd-ticket-guard-ree-public-key是根据rsa生成私钥1跟公钥1里的私钥1通过函数加密得到的。 最近我发现那个加密函数的加密原理是通过私钥1再用不同的rsa算法生成一对小的hex后的私钥2跟公钥2,私钥2比公钥2短,然后bd-ticket-guard-ree-public-key是通过公钥2加密得到的,req_sign则是通过加密私钥2得到的,然后我为了

ssl协议 Session ticket关联TLS流方法分析

ssl协议握手过程在上一篇中已经写过了  现在对比session id与 Session ticket 之间的区别 1.session id 通过ssl握手的时候由service发送给client端,session id 的信息(协商秘钥等)回报存在service端 每个session id大概会占用nginx 1m内存.使用它的好处是之后的ssl握手不需要再传证书验证了 只需要client端发

Buy a Ticket CodeForces - 938D

多源最短路题 当然不是指floyd 单源最短路就是起点集中只有一个元素{s} dis[i]就代表s到i的最短距离 多源最短路就是起点集中有多个元素{s1,s2...} dis[i]代表起点集合中某一个到i的最短距离 具体是哪个不知道 对于这个题起点n个各不相同 但是终点却可能有重复的点 逆向考虑 从终点出发跑向起点 正好对应上述多源最短路   #include <bits/stdc+

微信企业号开发Access_token的生命周期测试以及Js_ticket生命周期的测试

Access_token 官方文档的描述是有效期2小时,其实如果在这个有效期内再次调用,其有效期延长至4小时。举例说明:8点钟系统第一次调用接口申请该参数得到A,如果在有效期8:00-10:00期间内再次调用接口,则返回的还是A,但是A的有效期向后延长2小时,为8:00-12:00期间A都有效,但是在10:00后再次调用接口就不会返回A了,会返回B,在10:00-12:00期间会存在两个有效的A

通过ticket换取二维码

<?php header("Content-Type:text/html;charset=utf8");$ee = urlencode("gQFI8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL1RqallrX1RseXJLek41MU1BeFlYAAIE8aPXVgMEXAIAAA==");//在ticket里打开网页的token$url = "htt

php工单系统下载,PESCMS Ticket(客服工单系统)

PESCMSTicket客服工单系统,基于GPLv2协议发布,除了传统的站内工单提交模式,我们以全新的设计理念,基于Javascript语言开发的跨域工单提交,只需要一句JS,即可在任何页面嵌入工单,当然我们也支持站内工单!我们就是如此秀的工单系统。 相关软件软件大小版本说明下载地址 PESCMS Ticket(客服工单系统),基于GPLv2协议发布,除了传统的站内工单提交模式,我们以全新的设

客服工单php,PESCMS Ticket客服工单系统 v1.3.3

PESCMS Ticket客服工单系统(下称PT)是一款基于GPLv2协议发布的开源客服工单系统。除了传统的站内工单提交模式,我们以全新的设计理念,基于Javascript语言开发的跨域工单提交。实现在任何系统、任何页面,只需要调用一句Javascript代码,即可生成工单系统! PESCMS Ticket客服工单系统运行环境: PHP 5.6及以上版本 Mysql 5.5及以上版本 IE浏览器

PESCMS Ticket客服工单系统源码v1.3.6

介绍: PESCMS Ticket客服工单系统(下称PT)是一款基于GPLv2协议发布的开源客服工单系统。除了传统的站内工单提交模式,我们以全新的设计理念,基于Javascript语言开发的跨域工单提交。实现在任何系统、任何页面,只需要调用一句Javascript代码,即可生成工单系统! PESCMS Ticket客服工单系统运行环境: PHP 5.6及以上版本 Mysql 5.5及以上版本 I

[PHP]PESCMS Ticket客服工单系统 v1.3.19

源码下载:https://download.csdn.net/download/m0_66047725/88452232 PESCMS Ticket客服工单系统(下称PT)是一款基于GPLv2协议发布的开源客服工单系统。除了传统的站内工单提交模式,我们以全新的设计理念,基于Javascript语言开发的跨域工单提交。实现在任何系统、任何页面,只需要调用一句Javascript代码,即可生成工