点更新用法很巧妙的一道题。倒序很容易的找到该人的位置,而update操作中需要不断的变化下标才能合理的插入。看了别人写的代码,学习了。

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std; const int maxn = 2e5 + ;
int sumv[maxn << ], data[maxn]; void PushUp (int rt) {
sumv[rt] = sumv[rt << ] + sumv[rt << | ];
} void build (int l, int r, int rt) {
if (l == r) {
sumv[rt] = ;
return ;
}
int m = (l + r) / ;
build (l, m, rt << );
build (m + , r, rt << | );
PushUp (rt);
} void update (int p, int v, int l, int r, int rt) {
if (l == r) {
data[l] = v; sumv[rt] = ;
return ;
}
int m = (l + r) >> ;
if (sumv[rt * ] >= p) {
update (p, v, l, m, rt * );
} else {
update (p - sumv[rt * ], v, m + , r, rt * + );
}
PushUp(rt);
} int main () {
pair<int, int> p[maxn];
int n;
while (~scanf ("%d", &n)) {
for (int i = ; i < n; ++ i) {
scanf ("%d%d", &p[i].first, &p[i].second);
}
build (, n, );
for (int i = n - ; i >= ; -- i) {
update (p[i].first + , p[i].second, , n, );
}
for (int i = ; i <= n; ++ i) {
if (i == ) {
printf ("%d", data[i]);
} else {
printf (" %d", data[i]);
}
}
puts("");
}
return ;
}

【POJ】Buy Tickets(线段树)的更多相关文章

  1. poj 2828 Buy Tickets (线段树(排队插入后输出序列))

    http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissio ...

  2. POJ 2828 Buy Tickets 线段树 倒序插入 节点空位预留(思路巧妙)

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19725   Accepted: 9756 Desc ...

  3. POJ 2828 Buy Tickets (线段树 or 树状数组+二分)

    题目链接:http://poj.org/problem?id=2828 题意就是给你n个人,然后每个人按顺序插队,问你最终的顺序是怎么样的. 反过来做就很容易了,从最后一个人开始推,最后一个人位置很容 ...

  4. POJ 2828 Buy Tickets | 线段树的喵用

    题意: 给你n次插队操作,每次两个数,pos,w,意为在pos后插入一个权值为w的数; 最后输出1~n的权值 题解: 首先可以发现,最后一次插入的位置是准确的位置 所以这个就变成了若干个子问题, 所以 ...

  5. POJ 2828 Buy Tickets(线段树&#183;插队)

    题意  n个人排队  每一个人都有个属性值  依次输入n个pos[i]  val[i]  表示第i个人直接插到当前第pos[i]个人后面  他的属性值为val[i]  要求最后依次输出队中各个人的属性 ...

  6. POJ 2828 Buy Tickets(线段树单点)

    https://vjudge.net/problem/POJ-2828 题目意思:有n个数,进行n次操作,每次操作有两个数pos, ans.pos的意思是把ans放到第pos 位置的后面,pos后面的 ...

  7. [poj2828] Buy Tickets (线段树)

    线段树 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must ...

  8. 【poj2828】Buy Tickets 线段树 插队问题

    [poj2828]Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in ...

  9. poj-----(2828)Buy Tickets(线段树单点更新)

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 12930   Accepted: 6412 Desc ...

  10. Buy Tickets(线段树)

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 16607   Accepted: 8275 Desc ...

随机推荐

  1. inconvertible types; cannot cast 'android.supoort.v4.app.Fragment' to 'com.example.sevenun.littledemo.fragment.NewsTitleFragment'

    inconvertible types; cannot cast 'android.supoort.v4.app.Fragment' to 'com.example.sevenun.littledem ...

  2. 分页标签:pager-taglib使用指南

    一简介, Pager-taglib,支持多种风格的分页显示.实际上她是一个Jsp标签库,为在JSP上显示分页信息而设计的一套标签,通过这些标签的不同的组合,会形成多种不一样的分页页面,风格各异,她自带 ...

  3. hdu 5422 Rikka with Graph(简单题)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  4. 关于背景透明,文字不透明的最佳方法,兼容IE

    以背景黑色,透明度0.5举例 非IE:background:rgba(0,0,0,0.5); IE:filter:progid:DXImageTransform.Microsoft.gradient( ...

  5. hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. VB6.0连接MySQL数据库

    VB6.0连接MySQL数据库

  7. javascript之求最值

    求最值: var selections = $("#deliveryGridSalesOrGoods").datagrid('getRows'); var costPrice = ...

  8. 整理的sql sever一些数据库查询面试题

    当然,我整理的只是一些常见的面试题,具体数据库就不给了,相信大家能看懂!!! --2列出EMPLOYEES表中各部门的部门号,最高工资,最低工资 select Max(salary) as '最高工资 ...

  9. asp.net mvc4 远程验证

    [HttpGet] public ActionResult CheckToolsIdExists(string ToolsID) { using (BaseContext context = new ...

  10. javascript作用域和作用域链

    1.作用域 作用域,它是指对某一变量和方法具有访问权限的代码空间.当我们在定义变量的时候,会定义两种变量,一种是在全局环境下定义的变量,叫全局变量,一种是在函数中定义的变量叫局部变量.全局变量的作用域 ...