BNUOJ 2947 Buy Tickets
Buy Tickets
This problem will be judged on PKU. Original ID: 2828
64-bit integer IO format: %lld Java class name: Main
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
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct node{
int lt,rt,sum;
};
node tree[maxn<<];
int ans[maxn],ps[maxn],w[maxn],n;
void build(int lt,int rt,int v){
tree[v].lt = lt;
tree[v].rt = rt;
if(lt == rt){
tree[v].sum = ;
return;
}
int mid = (lt+rt)>>;
build(lt,mid,v<<);
build(mid+,rt,v<<|);
tree[v].sum = tree[v<<].sum + tree[v<<|].sum;
}
void update(int p,int val,int v){
int mid = (tree[v].lt+tree[v].rt)>>;
if(tree[v].lt == tree[v].rt){
tree[v].sum = ;
ans[tree[v].lt] = val;
return;
}
if(tree[v<<].sum >= p) update(p,val,v<<);
else update(p-tree[v<<].sum,val,v<<|);
tree[v].sum--;
}
int main() {
int i;
while(~scanf("%d",&n)){
for(i = ; i < n; i++)
scanf("%d %d",ps+i,w+i);
build(,n,);
for(i--; i >= ; i--)
update(ps[i]+,w[i],);
for(i = ; i < n; i++)
printf("%d ",ans[i]);
printf("%d\n",ans[i]);
}
return ;
}
BNUOJ 2947 Buy Tickets的更多相关文章
- POJ2828 Buy Tickets[树状数组第k小值 倒序]
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 19012 Accepted: 9442 Desc ...
- POJ 2828 Buy Tickets(线段树 树状数组/单点更新)
题目链接: 传送门 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Description Railway tickets were d ...
- Buy Tickets(线段树)
Buy Tickets Time Limit:4000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- 【poj2828】Buy Tickets 线段树 插队问题
[poj2828]Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in ...
- Buy Tickets
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 16010 Accepted: 7983 Descript ...
- poj-----(2828)Buy Tickets(线段树单点更新)
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 12930 Accepted: 6412 Desc ...
- poj 2828 Buy Tickets (线段树(排队插入后输出序列))
http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissio ...
- poj 2828 Buy Tickets【线段树单点更新】【逆序输入】
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 16273 Accepted: 8098 Desc ...
- 线段树(倒序操作):POJ 2828 Buy Tickets
Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in China, ...
随机推荐
- [完美方案+无懈可击]ubuntu 14.04(LTS) + GTX 980Ti显卡配置
安装好系统之后出现的问题: 1 不能上网:后来通过删除链接新建一个以太网链接(自动DHCP)重启莫名其妙就好使了. 2 分辨率只有两个:1024x ? 和 800x600. 分辨率低到让人头痛.通过查 ...
- 转】R利剑NoSQL系列文章 之 Hive
原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/3/ 感谢! Posted: Jul 27, 2013 Ta ...
- Android开发学习——android与服务器端数据交互
1.首先搭建服务器端. 使用MyEclipse开发工具 public class MyServlet extends HttpServlet { @Override protected void do ...
- H.264学习笔记3——帧间预测
帧间预测主要包括运动估计(运动搜索方法.运动估计准则.亚像素插值和运动矢量估计)和运动补偿. 对于H.264,是对16x16的亮度块和8x8的色度块进行帧间预测编码. A.树状结构分块 H.264的宏 ...
- Node.js——body方式提交数据
引入核心模块 http,利用其 api(http.createServer) 返回一个 http.server 实例,这个实例是继承于net.Server,net.Server 也是通过net.cre ...
- jQuery addClass removeClass toggleClass方法概述
通过动态改变类名(class),可以让其修改元素呈现出不同的效果.在HTML结构中里,多个class以空格分隔,当一个节点(或称为一个标签)含有多个class时,DOM元素响应的className属性 ...
- 【C++】朝花夕拾——表达式树
表达式树: 叶子是操作数,其余结点为操作符,是二叉树的其中一种应用 ====================我是分割线====================== 一棵表达式树如下图: 若是对它做中序 ...
- 使用Gson解析Json数组遇到的泛型类型擦除问题解决方法
谷歌Gson转换Json串有如下方法: public Object fromJson(String json, Type typeOfT);1可以使用它进行数组解析.如下,使用此方法解析Json串为类 ...
- hibernate cascade属性
cascade属性是存在于set标签中,用来做级联删除和保存. 它的值有以下几种: 1)默认值是none,不做级联动作: 2)save-update:级联保存 3)delete:级联删除 4)all: ...
- asp 数据库 模块化 - 思路是没一个页面有一个自己的数据类 这里用nPath表示
<!--#include file="db_class.asp" --> <% '当前页面数据 nPath = "..\..\.." 't模块 ...