poj 2828(线段树单点更新)
Time Limit: 4000MS | Memory Limit: 65536K | |
Total Submissions: 18561 | Accepted: 9209 |
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.
Source
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#define N 250005
using namespace std; int tree[N<<]; ///当前结点剩余的容量
int a[N],v[N],ans[N];
void pushup(int idx){
tree[idx] = tree[idx<<]+tree[idx<<|];
}
void build(int l,int r,int idx){
if(l==r){
tree[idx] = ;
return;
}
int mid = (l+r)>>;
build(l,mid,idx<<);
build(mid+,r,idx<<|);
pushup(idx);
}
void update(int num,int v,int l,int r,int idx){
if(l==r){
tree[idx]= ;
ans[l] = v;
return;
}
int mid = (l+r)>>;
if(tree[idx<<]>=num){ ///左子树还有位置可以插
update(num,v,l,mid,idx<<);
}else{ ///往右子树插
update(num-tree[idx<<],v,mid+,r,idx<<|);
}
pushup(idx);
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
build(,n,);
for(int i=;i<=n;i++){
scanf("%d%d",&a[i],&v[i]);
a[i]++;
}
for(int i=n;i>=;i--){
update(a[i],v[i],,n,);
}
for(int i=;i<=n;i++){
printf("%d ",ans[i]);
}
printf("\n");
}
return ;
}
poj 2828(线段树单点更新)的更多相关文章
- POJ 2828 (线段树 单点更新) Buy Tickets
倒着插,倒着插,这道题是倒着插! 想一下如果 Posi 里面有若干个0,那么排在最前面的一定是最后一个0. 从后往前看,对于第i个数,就应该插在第Posi + 1个空位上,所以用线段树来维护区间空位的 ...
- POJ 2828 线段树单点更新 离线搞
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- POJ 2886 线段树单点更新
转载自:http://blog.csdn.net/sdj222555/article/details/6878651 反素数拓展参照:http://blog.csdn.net/ACdreamers/a ...
- poj 2892---Tunnel Warfare(线段树单点更新、区间合并)
题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...
- POJ 1804 Brainman(5种解法,好题,【暴力】,【归并排序】,【线段树单点更新】,【树状数组】,【平衡树】)
Brainman Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10575 Accepted: 5489 Descrip ...
- POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)
POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...
- POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)
POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- HDU 1166 敌兵布阵(线段树单点更新)
敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...
随机推荐
- MDK5.13新建工程步骤
http://www.stmcu.org/module/forum/thread-600249-1-1.html 本人也是接触stm32没多久,之前用的MDK是5.1,现在用的是5.13,MDK5.0 ...
- makefile使用笔记(二)变量
By francis_hao Oct 30,2017 makefile中可以使用变量,变量有多种类型,下面分别介绍 简单变量 简单变量的命名规则和c语言一致. 给变量赋值就表示创建了这个变量 ...
- selenium - 查看selenium版本信息
1. pip list 2. pip show selenium 3. cmd>>python >>> import selenium>>> help( ...
- bzoj4873 [Shoi2017]寿司餐厅
Input 第一行包含两个正整数n,m,分别表示这家餐厅提供的寿司总数和计算寿司价格中使用的常数. 第二行包含n个正整数,其中第k个数ak表示第k份寿司的代号. 接下来n行,第i行包含n-i+1个整数 ...
- K8s仪表盘
{ "__inputs": [ { "name": "DS_TEST-ENVIORMENT-K8S", "label": ...
- TypeError: only integer scalar arrays can be converted to a scalar index
TypeError: only integer scalar arrays can be converted to a scalar index 觉得有用的话,欢迎一起讨论相互学习~Follow Me ...
- c语言时间计算
C语言使用time_t结构体表示时间戳,它本质上是个long类型. 我们可以使用如下函数获取当前时间的时间戳: time_t time(time_t* timer) 函数功能:得到从标准计时点(一般是 ...
- MyEclipse+Weblogic+Oracle+PLSQL配置注意事项
Weblogic配置详情:<Weblogic安装与配置图文详解>Oracle+PLSQL配置详情:<PL/SQL访问远程Oracle服务器(多种方式)>MyEclipse配置: ...
- 图:centrality
[定义]Centrality:图中每个节点v的相对重要度c(v),重要度是什么可根据具体应用定义. [估计方法] Degree centrality Betweenness centrality Cl ...
- @PathParam 和 @QueryParam
今天调试一个上传功能,客户端手持机发送数据,在URL中附加一个参数,后台用@PathParam接收,但是报错,无法获取这个参数. url:http://192.168.1.3/web1_service ...