[POJ2828] Buy Tickets(待续)
[POJ2828] Buy Tickets(待续)
题目大意:多组测试,每组给出\(n\)条信息\((a,b)\),表示\(b\)前面有\(a\)个人,顺序靠后的信息优先级高
Solution.1
由后向前看,每个遇到的都是确定位置的,最后的人选定的位置不会改变,同样因为是倒叙输入,在第\(i\)个人后插队,也就是说他的前面一定要留下\(i\)个空格。
形象一点就是这样:

从后往前,去查找第一个大于所需要空白的位置。用线段树维护空格数目即可
Code.1
#include <iostream>
#include <cstdio>
#include <algorithm>
const int N = 2e5 + 10;
int n;
int a[N], b[N];
int num[N << 2], spa[N << 2];
inline void pushup(int cur){
spa[cur] = spa[cur << 1] + spa[cur << 1 | 1];
return;
}
void build(int cur, int l, int r){
int mid = l + ((r - l) >> 1);
if(l == r){
spa[cur] = 1;
num[cur] = 0;
}else{
build(cur << 1, l, mid);
build(cur << 1 | 1, mid + 1, r);
pushup(cur);
}
}
void update(int cur, int l, int r, int la, int lb){
if(l == r){
spa[cur] = 0;
num[cur] = lb;
}else{
int mid = l + ((r - l) >> 1);
if(spa[cur << 1] >= la){
update(cur << 1, l, mid, la, lb);
}else{
update(cur << 1 | 1, mid + 1, r, la - spa[cur << 1], lb);
}
pushup(cur);
}
}
inline void print(int cur, int l, int r){
int mid = l + ((r - l) >> 1);
if(l == r){
printf("%d ", num[cur]);
return;
}else{
print(cur << 1, l, mid);
print(cur << 1 | 1, mid + 1, r);
}
return;
}
int main(){
while(scanf("%d", &n) != EOF){
build(1, 1, n);
for(int i = 1; i <= n; ++i){
scanf("%d %d", &a[i], &b[i]);
a[i] ++;
}
for(int i = n; i; --i){
update(1, 1, n, a[i], b[i]);
}
print(1, 1, n);
printf("\n");
}
return 0;
}
Solution.2
用splay优雅接上
Code.2
[POJ2828] 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 Total Submissions: 12930 Accepted: 6412 Desc ...
- POJ2828 Buy Tickets 【线段树】+【单点更新】+【逆序】
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 12296 Accepted: 6071 Desc ...
- poj2828 Buy Tickets (线段树 插队问题)
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 22097 Accepted: 10834 Des ...
- poj-2828 Buy Tickets(经典线段树)
/* Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 10207 Accepted: 4919 Descr ...
- POJ2828 Buy Tickets [树状数组,二分答案]
题目传送门 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 22611 Accepted: 110 ...
- POJ2828 Buy Tickets 树状数组
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- poj-2828 Buy Tickets(线段树,排队问题,逆向思维)
题目地址:POJ 2828 Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Yea ...
- [poj2828] Buy Tickets (线段树)
线段树 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must ...
随机推荐
- 在kubernetes集群里集成Apollo配置中心(3)之交付Apollo-portal至Kubernetes集群
1.执行apollo-portal数据库脚本 apollo-portal数据库脚本链接:https://raw.githubusercontent.com/ctripcorp/apollo/1.5.1 ...
- config file language All In One
config file language All In One YAML YAML Ain't Markup Language .yaml / .yml https://yaml.org/ https ...
- HTML5 drag & drop & H5 DnD
HTML5 drag & drop H5 DnD https://html5demos.com/ demos https://html5demos.com/dnd-upload https:/ ...
- MDN Browser Compatibility Report 2020
MDN Browser Compatibility Report 2020 top pain point https://mdn-web-dna.s3-us-west-2.amazonaws.com/ ...
- 如何用 js 实现一个 bind 函数
如何用 js 实现一个 bind 函数 原理 实现方式 总结 refs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc ...
- Array.fill & array padding
Array.fill & array padding arr.fill(value[, start[, end]]) https://developer.mozilla.org/en-US/d ...
- chroot vs docker
chroot vs docker chroot Linux A chroot on Unix operating systems is an operation that changes the ap ...
- Flutter 1.17.x
Flutter 1.17.x Flutter (Channel stable, v1.17.3, on Mac OS X 10.15.5 19F101, locale en-CN) https://f ...
- 在线预览word,excel,ppt
https://view.officeapps.live.com/op/view.aspx?src=服务器地址微软提供的地址拼接自己的可以预览了拼接自己的服务器地址可以在线预览
- VAST助推NGK公链热度升温,日活超过以太坊!
在区块链市场,如果说过去是比特币和以太坊的时代,那么现在和未来绝对是NGK的时代. NGK公链的出现,让区块链市场看到了新的希望.它不仅仅是开放的和可编程的,而且是低Gas燃耗的,以及创新共识机制的. ...