poj 2828 buy Tickets 用线段树模拟带插入的队列
Buy Tickets
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=2795
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
Sample Input
0 77
1 51
1 33
2 69
4
0 20523
1 19243
1 3890
0 31492
Sample Output
31492 20523 3890 19243
HINT
题意
给你一个队列,有一群人来插队,然后让你输出最后队列的样子
题解:
感觉是个很傻B的题,但是为什么我非得用线段树来做呢?= =
vector亲测被T掉
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200050
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/*
;
inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
} struct node
{
int l,r,v;
}; node a[maxn*]; void build(int x,int l,int r)
{
a[x].l=l,a[x].r=r;
a[x].v=r-l+;
if(l==r)
return;
int mid=(l+r)>>;
build(x<<,l,mid);
build(x<<|,mid+,r);
} int update(int x,int val)
{
int l=a[x].l,r=a[x].r;
if(l==r)
{
a[x].v=;
return l;
}
else
{
int pos=;
if(a[x<<].v>=val)
pos=update(x<<,val);
else
pos=update(x<<|,val-a[x<<].v);
a[x].v=a[x<<].v+a[x<<|].v;
return pos;
}
} int n;
int b[maxn];
int c[maxn];
int pos[maxn];
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(a,,sizeof(a));
build(,,n);
for(int i=;i<n;i++)
b[i]=read(),c[i]=read();
for(int i=n-;i>=;i--)
pos[update(,b[i]+)]=c[i];
for(int i=;i<=n;i++)
printf("%d ",pos[i]);
puts("");
}
}
poj 2828 buy Tickets 用线段树模拟带插入的队列的更多相关文章
- poj 2828 Buy Tickets 【线段树点更新】
题目:id=2828" target="_blank">poj 2828 Buy Tickets 题意:有n个人排队,每一个人有一个价值和要插的位置,然后当要插的位 ...
- POJ 2828 Buy Tickets (线段树 单点更新 变形)
题目链接 题意:有N个人排队,给出各个人想插队的位置和标识,要求输出最后的序列. 分析:因为之前的序列会因为插队而变化,如果直接算时间复杂度很高,所以可以用 线段树逆序插入,把序列都插到最后一层,le ...
- POJ 2828 Buy Tickets(线段树 树状数组/单点更新)
题目链接: 传送门 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Description Railway tickets were d ...
- POJ - 2828 Buy Tickets(线段树单点更新)
http://poj.org/problem?id=2828 题意 排队买票,依次给出当前人要插队的位置,每个人有个编号,然后问你最后整个的序列是什么? 分析 最后一个人的要插入的位置是确定的,所以逆 ...
- poj 2828 Buy Tickets【线段树单点更新】【逆序输入】
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 16273 Accepted: 8098 Desc ...
- poj 2828 Buy Tickets (线段树 单节点 查询位置更新)
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 15533 Accepted: 7759 Desc ...
- POJ 2828 Buy Tickets (线段树 || 树状数组)
题目大意 一些小朋友在排队,每次来一个人,第i个人会插到第x个人的后面.权值为y.保证x∈[0,i-1]. 按照最后的队伍顺序,依次输出每个人的权值. 解题分析 好气吖.本来是在做splay练习,然后 ...
- poj 2828 Buy Tickets【线段树 单点更新】
倒着插,先不理解意思,后来看一篇题解说模拟一下 手动模拟一下就好理解了----- 不过话说一直写挫---一直改啊----- 好心塞------ #include <cstdio> #inc ...
- 【POJ】2828 Buy Tickets(线段树+特殊的技巧/splay)
http://poj.org/problem?id=2828 一开始敲了个splay,直接模拟. tle了.. 常数太大.. 好吧,说是用线段树.. 而且思想很拽.. (貌似很久以前写过貌似的,,) ...
随机推荐
- perf + 火焰图分析程序性能
1.perf命令简要介绍 性能调优时,我们通常需要分析查找到程序百分比高的热点代码片段,这便需要使用 perf record 记录单个函数级别的统计信息,并使用 perf report 来显示统计结果 ...
- 配置tomcat多域名访问
C:\Windows\System32\drivers\etc下的hosts文件改成:127.0.0.1 localhost 127.0.0.1 www.greenmood.net 127.0.0.1 ...
- Linux下的压缩解压缩
Linux下最常用的打包程序就是tar了,使用tar程序打出来的包我们常称为tar包,tar包文件的命令通常都是以.tar结尾的.生成tar包后,就可以用其它的程序来进 行压缩了,所以首先就来讲讲t ...
- python 并发爬虫的快感
import time from tomorrow import threads from requests_html import HTMLSession session=HTMLSession() ...
- Nim 游戏、SG 函数、游戏的和
Nim游戏 Nim游戏定义 Nim游戏是组合游戏(Combinatorial Games)的一种,准确来说,属于“Impartial Combinatorial Games”(以下简称ICG).满足以 ...
- linux系统性能排查命令
[top] 命令可以动态查看当前系统的资源情况,以及占用资源的命令列表 用法: - ctrl + c / q : 停止此命令运行 - c : 展示完整的命令 - [top -bn1]:可以不动态的展示 ...
- 防范SQL注入
使用占位符的方式写查询语句hibernate
- 简易web server之python实现
网络编程一项基本功是socket编程,包括TCP socket,UDP socket的客户端.服务器端编程. 应用层的各路协议如http,smtp,telnet,ftp等都依赖于传输层的TCP或者UD ...
- 洛谷P1319压缩技术 题解
题目传送门 这道题是入门难度的题.特别水...QWQ...... #include<bits/stdc++.h> using namespace std; *],top; int main ...
- 一道关于数据库(经典父子级 ID 关联)更新题,大家帮忙想想还有其它解决思路没有?
昨天,一同事发过来的一道数据库题目,就是哪种经典的父子级 ID 在同一数据库表中设计类型.需要在原表中添加一个字段,同时,将该节点的父子级详细信息插入到原表新增的一字段中,具体效果如下图. AreaC ...